Showing how I would approach coding interviews with data structures & algo problems.
-
Multiple approaches or optimizations for some problems.
(Search 'Approach 1')
-
Untimed as for problems that I got stuck, came back to them at a later point in time for fresh perspectives.
(Click)
Most problems were analyzed and broken down into following sections when solving them.# Input
# Output
# General cases & example I/O
Q: (Clarification Question)
A: (Clarification Answer)
# Edge cases
Base case if exists
# High level
# Algorithm/Pseudo
# Time/Space complexity
Code
# | LeetCode Problem Link | My Analysis & Code | Time | Space |
---|---|---|---|---|
8 | String to Integer (atoi) | LinearParsing.swift | O(n) | O(1) |
38 | Count and Say | Counting.swift | O(x^n) | O(x^n) |
103 | Binary Tree Zigzag Level Order Traversal | BFS.py | O(N) | O(N) |
153 | Find Minimum in Rotated Sorted Array | Binary Search.py | O(log N) | O(1) |
162 | Find Peak Element | Binary Search.py | O(log N ) | O(1) |
209 | Minimum Size Subarray Sum | Two Pointers.py | O(N) | O(1) |
649 | Dota2 Senate | Two Queues.py | O(N) | O(N) |
658 | Find K Closest Elements | Binary Search.py | O(log N + k) | O(1) |
852 | Peak Index in a Mountain Array | Binary Search.py | O(log N) | O(1) |
921 | Minimum Add to Make Parentheses Valid | Counting.py | O(N) | O(1) |
986 | Interval List Intersections | Two Pointers.swift | O(N + M) | O(N + M) |
1115 | Print FooBar Alternately | Semaphore.py | - | - |
1472 | Design Browser History | Two Stacks.py | Visit: O(1) Back & Forward: O(min(k, h)) |
O(N * M) |
# | LeetCode Problem Link | My Analysis & Code | Time | Space |
---|---|---|---|---|
257 | Binary Tree Paths | DFS.py | O(N log N) | O(N log N) |
389 | Find the Difference | Approach 1: HashMap.py | O(N) | O(1) |
Approach 2: Bitwise XOR.py | O(N) | O(1) | ||
1108 | Defanging an IP Address | Linear Search.py | O(N) | O(N) |
1114 | Print in Order | Concurrency Lock.py | - | - |
1232 | Check If It Is a Straight Line | Slope.py | O(N) | O(1) |
Saved analysis notes of problems I got stuck on the first try. May return to them once I 'forget' the problem context & my initial approach.
To be updated later