My Python solutions to NeetCode data structures and algorithms problems, synced automatically on each submission. When a problem has several submissions, the later ones are usually a more efficient rewrite.
| Problem | Approach | Time | Solution |
|---|---|---|---|
| Contains Duplicate | Hash set of seen values | O(n) | Python |
| Valid Anagram | Character frequency maps (earlier: sorting) | O(n) | Python |
| Two Sum | Hash map of value → index | O(n) | Python |
| Top K Frequent Elements | Counter + heap |
O(n log k) | Python |
| Problem | Approach | Time | Solution |
|---|---|---|---|
| Valid Palindrome | Two pointers skipping non-alphanumerics, O(1) space (earlier: filtered string reversal) | O(n) | Python |
| Two Sum II | Two pointers on the sorted array | O(n) | Python |
| Problem | Approach | Time | Solution |
|---|---|---|---|
| Reverse Linked List | Iterative pointer reversal | O(n) | Python |
| Merge Two Sorted Lists | Dummy head + tail pointer | O(n + m) | Python |
| Linked List Cycle | Floyd's slow/fast pointers | O(n) | Python |
| Remove Nth Node From End | Dummy node + fast pointer with an n-step lead | O(n) | Python |