aa Flashcards

1
Q

Two Sum

A

Uses a hash map to store seen numbers and their indices; for each element, checks if the complement (target minus current value) exists in the map, returning the pair in a single pass.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Palindrome Number

A

Converts the integer into its string form and compares it to its reverse to determine if it reads the same forwards and backwards, immediately excluding negative values.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Roman to Integer

A

Processes the Roman numeral from right to left, adding values but subtracting when a smaller symbol precedes a larger one to handle subtractive notation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Longest Common Prefix

A

Starts with the first string as a candidate prefix and iteratively shortens it until all other strings in the array share that starting substring.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Valid parentheses

A

Uses a stack to push opening brackets and verifies each closing bracket matches the most recent opener, ensuring all brackets are paired correctly and the stack is empty at the end.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Merge Two Sorted Lists

A

Recursively compares the head nodes of two sorted linked lists, appending the smaller node to the merged result and proceeding until one list is exhausted.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Remove duplicates from sorted array

A

Uses two pointers—one to build the unique portion and one to scan through the array—overwriting duplicates in place and returning the length of the unique segment.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Remove Element

A

Iterates through the array with a write pointer that only advances when encountering values not equal to the target, effectively overwriting unwanted elements in place.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Find the index of the First Occurence in a string

A

Leverages built‑in substring search to return the index of the first occurrence of the needle in the haystack, or –1 if it’s not found.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Search insert position

A

Applies binary search on a sorted array to find either the exact target or the correct insertion index in O(log n) time.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Length of Last word

A

Splits the string on whitespace and returns the length of the final nonempty segment, naturally ignoring any trailing spaces.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Plus one

A

Starts from the least significant digit, increments it while handling carry; if all digits roll over (e.g., 999 → 1000), prepends a new digit.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Add Binary

A

Simulates manual binary addition by iterating from the end of two binary strings, summing bits and carry, then constructing the result from least to most significant bit.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Sqrt(x)

A

Uses binary search to find the greatest integer whose square is ≤ x by narrowing down the search interval until convergence.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Climbing stairs

A

Recognizes the recurrence identical to Fibonacci: the number of ways to reach step n equals the sum of ways to reach steps n–1 and n–2, computed iteratively.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly