| Problem Names | Solution Writeups | Code |
|---|---|---|
| Contains Duplicate |
Create set and check if current character already exists in the set. |
|
| Valid Anagram | Create character reference array (size of 26), count the frequency of the character and ensure both string has same character frequency. | |
| Two Sum |
Create map, record index of each value, and try to find (target - current_value) in the map, if found return the solution. |
|
| Group Anagrams |
Create a map that maps sorted string in the array to a vector of string. Sorted string as the key will ensure group correctness |
|
| Top K Frequent Elements |
Create a map to count frequency, by knowing the maximum frequency, create another vector of vector, which will store the numbers according to the frequency |
|
| Product of Array Except Self |
First find the product of all numbers in the array, and count the number of zero in the array, if zero_count > 1 then the ans will be all zeros, else if zero_count == 1, calculate the max_product without multiplying 0, and then for position of number 0, return max_product value, the rest will be 0. |
|
| Valid Sudoku |
Check if each row and col contains duplicates, for square checking, loop for each row, and check for each column, and separates square 1, 2 and 3. |
|
| Longest Consecutive Sequence |
Change vector to set, find how many possible sequence in the vector (by checking if n - 1 exists given n), if n is the start of the sequence, continuously check if n+1 exists. Record the longest length. |