This repository contains my solutions to LeetCode problems. I will be updating this repository with my solutions as I solve more problems. I have included a test suite for each solution.
The test suite can be run using the following command in the repository directory:
pytest- Arrays & Hashing
- Two Pointers
- Sliding Window
- Stack
- Matrix
- Intervals
- Linked List
- Binary Tree General
- Binary Search Tree
- Graph General
| # | Title | Solution | Time | Space | Difficulty | Tag | Note | 
|---|---|---|---|---|---|---|---|
| 1 | Two Sum | Python | O(n) | O(n) | Easy | ||
| 49 | Group Anagrams | Python | O(NK) | O(NK) | Medium | N is the number of strings and K is the maximum length of a single string | |
| 88 | Merge Sorted Array | Python | O(n + m) | O(1) | Easy | Two-Pointers, Reverse | |
| 128 | Longest Consecutive Sequence | Python | O(n) | O(n) | Medium | Tricky solution! | |
| 135 | Candy | Python | O(n) | O(n) | Hard | Enjoyed solving it! | |
| 217 | Contains Duplicate | Python | O(n) | O(n) | Easy | ||
| 238 | Product of Array Except Self | Python | O(n) | O(1) | Medium | Interesting solution! | |
| 242 | Valid Anagram | Python | O(n) | O(n) | Easy | Given Unicode characters support for Python3, the follow-up question is irrelevant | |
| 271 | Encode and Decode Strings | Python | O(n) | O(n) | Medium | ||
| 347 | Top K Frequent Elements | Python | O(N*log(K)) | O(N + K) | Medium | Requires MinHeap | |
| 383 | Ransom Note | Python | O(n) | O(1) | Easy | Fixed List | 
| # | Title | Solution | Time | Space | Difficulty | Tag | Note | 
|---|---|---|---|---|---|---|---|
| 11 | Container With Most Water | Python | O(n) | O(1) | Medium | ||
| 15 | 3Sum | Python | O(n^2) | O(1) | Medium | ||
| 42 | Trapping Rain Water | Python O(n), Python O(1) | O(n) | O(n) or O(1) | Hard | Initially proposed an O(n) space complexity solution, but discovered an O(1) alternative. | |
| 125 | Valid Palindrome | Python | O(n) | O(1) | Easy | ||
| 167 | Two Sum II - Input Array is Sorted | Python | O(n) | O(1) | Medium | 
| # | Title | Solution | Time | Space | Difficulty | Tag | Note | 
|---|---|---|---|---|---|---|---|
| 3 | Longest Substring Without Repeating Characters | Python | O(n) | O(min(n, m)), n being size of the string and m being the size of the alphabet | Medium | A better solution would be to jump to the point where we have a valid string | |
| 76 | Minimum Window Substring | Python | O(m + n), m being size of sand n the size oft | O(l), l being the number of unique characters in t | Hard | ||
| 121 | Best Time to But and Sell Stock | Python | O(n) | O(1) | Easy | ||
| 209 | Minimum Size Subarray Sum | Python | O(n) | O(1) | Medium | ||
| 239 | Sliding Window Maximum | Python | O(n), n being the length of nums | O(k), k being the window size | Hard | ||
| 424 | Longest Repeating Character Replacement | Python | O(n) | O(1) | Medium | ||
| 567 | Permutation in String | Python | O(n), n being the length of s2 | O(k), k being the length of s1 | Medium | 
| # | Title | Solution | Time | Space | Difficulty | Tag | Note | 
|---|---|---|---|---|---|---|---|
| 20 | Valid Parentheses | Python | O(n) | O(n) | Easy | ||
| 22 | Generate Parentheses | Python | O(4^n/sqrt(n)) | O(n) | Medium | ||
| 150 | Evaluate Reverse Polish Notation | Python | O(n) | O(n) | Medium | ||
| 155 | Min Stack | Python | O(1) | O(1) | Medium | Tuple in stack is interesting ! | 
| # | Title | Solution | Time | Space | Difficulty | Tag | Note | 
|---|---|---|---|---|---|---|---|
| 36 | Valid Sudoku | Python | O(1) | O(1) | Medium | 
| # | Title | Solution | Time | Space | Difficulty | Tag | Note | 
|---|---|---|---|---|---|---|---|
| 228 | Summary Ranges | Python | O(n) | O(n) | Easy | 
| # | Title | Solution | Time | Space | Difficulty | Tag | Note | 
|---|---|---|---|---|---|---|---|
| 141 | Linked List Cycle | Python | O(n) | O(1) | Easy | 
| # | Title | Solution | Time | Space | Difficulty | Tag | Note | 
|---|---|---|---|---|---|---|---|
| 104 | Maximum Depth of Binary Tree | Python | O(n) | O(1) | Easy | DFS | Use FIFO for BFS | 
| # | Title | Solution | Time | Space | Difficulty | Tag | Note | 
|---|---|---|---|---|---|---|---|
| 199 | Binary Tree Right Side View | Python | O(n) | O(w) where w is the maximum width of the binary tree | Medium | 
| # | Title | Solution | Time | Space | Difficulty | Tag | Note | 
|---|---|---|---|---|---|---|---|
| 530 | Minimum Absolute Difference in BST | Python | O(n) | O(1) | Easy | In-order traversal | 
| # | Title | Solution | Time | Space | Difficulty | Tag | Note | 
|---|---|---|---|---|---|---|---|
| 200 | Number of Islands | Python | O(n * m) | O(1) | Medium |