A selection of problems implemented in TypeScript.
1. 🟢 🙂 Contains Duplicate
- DS: Set
- Algorithm: Count difference in length.
2. 🟢 🙂 Valid Anagram
- DS: List
- Algorithm: Count frequency of each character.
3. 🟢 🙂 Two Sum
- DS: Map
- Algorithm: Test for compliment.
4. 🟠 🙂 Group Anagrams
- DS: Map
- Algorithm: Sort.
5. 🟠 🙂 Top K Frequent Elements
- DS: Map
- Algorithm: Sort.
6. 🟠 🙂 Product of Array Except Self
- DS: List
- Algorithm: Prefix & Postfix.
7. 🟠 🙂 Valid Soduko
- DS: Map of Sets
- Algorithm: Loop rows, columns to get cell. Test if cell is contained in respective row, column, or square set of values using a unique set key. Square keys are generated by banding and intersecting row and column indices using Math.floor and square dimension of 3:
${row}-${column}
.
8. 🟠 😐 String Encode and Decode
- DS: List
- Algorithm: Nested while loop.
9. 🟠 🙂 Longest Consecutive Sequence
- DS: Set
- Algorithm:
- CREATE numbers Set.
- ITERATE numbers.
- GET sequence start. IF previous number IS NOT IN Set.
- SET sequence length IF longer THAN existing.
- RETURN sequence length.
1. 🟢 🙂 Valid Parentheses
- DS: Stack
- Algorithm:
- ITERATE brackets.
- IF open THEN push.
- ELSE IF pop != matching bracket THEN RETURN false.
- ELSE RETURN stack = empty.
2. 🟠 🙂 Min Stack
- DS: Stack x 2
- Algorithm:
- WHEN push IF value < MinStack top THEN push MinStack.
- WHEN pop IF value = MinStack top THEN pop MinStack.
- DS: Stack
- Algorithm:
- IF operator THEN evaluate two integers on Stack.
- ELSE push integer to Stack.
4. 🟠 🙂 Generate Parentheses
- Heuristics: Backtracking, Recursion
- DS: Stack
- Algorithm: Call generator function recursively.
5. 🟠 🙁 Daily Temperatures
- Heuristics: Greedy
- DS: Stack
- Algorithm: ?
6. 🟠 🙂 Car Fleet
- Heuristics: Greedy
- DS: Stack
- Algorithm:
- Zip distance and speed.
- Sort descending distance.
- ITERATE zipped cars.
- Calculate ETA THEN push to Stack.
- IF car ETA < car ahead THEN pop and merge car from Stack.
1. 🟢 🙂 Valid Palindrome
- Algorithm: Walk two pointers in opposite directions.
- Algorithm:
- Walk two pointers in possite directions
- IF sum > target THEN decrease endPointer
- IF sum < target THEN increase startPointer