Tree | Binary Tree | Depth-First Search | Breadth-First Search | Binary Search | Array | Dynamic Programming | Stack | Design | Two Pointers | Greedy | Math | Bit Manipulation | Hash Table | Heap (Priority Queue) | Graph | Topological Sort | String | Sliding Window | Linked List | Recursion | Backtracking | Sorting | Union Find | Minimum Spanning Tree | Trie | Prefix Sum | Divide and Conquer | Grid | Binary Search Tree | Queue | Counting | Sort | Easy | Medium | Hard |
| LC# | Problem | Level | Python Solution(s) | Unittest |
|---|---|---|---|---|
| 4 | Median of Two Sorted Arrays | Hard | Sol 1, Sol 2, Sol 3 | Test |
| 23 | Merge k Sorted Lists | Hard | Sol 1, Sol 2 | Test |
| 42 | Trapping Rain Water | Hard | Sol 1, Sol 2, Sol 3 | Test |
| 72 | Edit Distance | Hard | Sol 1, Sol 2 | Test |
| 76 | Minimum Window Substring | Hard | Solution | Test |
| 84 | Largest Rectangle in Histogram | Hard | Solution | Test |
| 127 | Word Ladder | Hard | Solution | Test |
| 224 | Basic Calculator | Hard | Sol 1, Sol 2, Sol 3 | Test |
| 269 | Alien Dictionary | Hard | Sol 1, Sol 2 | Test |
| 295 | Find Median from Data Stream | Hard | Solution | Test |
| 297 | Serialize and Deserialize Binary Tree | Hard | Solution | Test |
| 312 | Burst Balloons | Hard | Sol 1, Sol 2, Sol 3 | Test |
| 588 | Design In-Memory File System | Hard | Sol 1, Sol 2, Sol 3 | Test |
| 1235 | Maximum Profit in Job Scheduling | Hard | Sol 1, Sol 2, Sol 3 | Test |
| 1537 | Get The Maximum Score | Hard | Solution | Test |
| 2050 | Parallel Courses III | Hard | Sol 1, Sol 2 | Test |
| LC# | Problem | Level | Python Solution(s) | Unittest |
|---|---|---|---|---|
| 104 | Maximum Depth of Binary Tree | Easy | Solution | Test |
| 110 | Balanced Binary Tree | Easy | Solution | Test |
| 226 | Invert Binary Tree | Easy | Sol 1, Sol 2 | Test |
| 543 | Diameter of Binary Tree | Easy | Solution | Test |
| 98 | Validate Binary Search Tree | Medium | Sol 1, Sol 2, Sol 3 | Test |
| 102 | Binary Tree Level Order Traversal | Medium | Sol 1, Sol 2 | Test |
| 105 | Construct Binary Tree from Preorder and Inorder Traversal | Medium | Sol 1, Sol 2 | Test |
| 199 | Binary Tree Right Side View | Medium | Sol 1, Sol 2 | Test |
| 230 | Kth Smallest Element in a BST | Medium | Sol 1, Sol 2 | Test |
| 235 | Lowest Common Ancestor of a Binary Search Tree | Medium | Sol 1, Sol 2 | Test |
| 236 | Lowest Common Ancestor of a Binary Tree | Medium | Sol 1, Sol 2 | Test |
| 1490 | Clone N-ary Tree | Medium | Sol 1, Sol 2 | Test |
| 297 | Serialize and Deserialize Binary Tree | Hard | Solution | Test |
| LC# | Problem | Level | Python Solution(s) | Unittest |
|---|---|---|---|---|
| 104 | Maximum Depth of Binary Tree | Easy | Solution | Test |
| 110 | Balanced Binary Tree | Easy | Solution | Test |
| 226 | Invert Binary Tree | Easy | Sol 1, Sol 2 | Test |
| 543 | Diameter of Binary Tree | Easy | Solution | Test |
| 98 | Validate Binary Search Tree | Medium | Sol 1, Sol 2, Sol 3 | Test |
| 102 | Binary Tree Level Order Traversal | Medium | Sol 1, Sol 2 | Test |
| 105 | Construct Binary Tree from Preorder and Inorder Traversal | Medium | Sol 1, Sol 2 | Test |
| 199 | Binary Tree Right Side View | Medium | Sol 1, Sol 2 | Test |
| 230 | Kth Smallest Element in a BST | Medium | Sol 1, Sol 2 | Test |
| 235 | Lowest Common Ancestor of a Binary Search Tree | Medium | Sol 1, Sol 2 | Test |
| 236 | Lowest Common Ancestor of a Binary Tree | Medium | Sol 1, Sol 2 | Test |
| 298 | Binary Tree Longest Consecutive Sequence | Medium | Solution | Test |
| 297 | Serialize and Deserialize Binary Tree | Hard | Solution | Test |
| LC# | Problem | Level | Python Solution(s) | Unittest |
|---|---|---|---|---|
| 278 | First Bad Version | Easy | Solution | Test |
| 704 | Binary Search | Easy | Solution | Test |
| 1228 | Missing Number In Arithmetic Progression | Easy | Sol 1, Sol 2 | Test |
| 33 | Search in Rotated Sorted Array | Medium | Solution | Test |
| 34 | Find First and Last Position of Element in Sorted Array | Medium | Solution | Test |
| 300 | Longest Increasing Subsequence | Medium | Sol 1, Sol 2, Sol 3 | Test |
| 981 | Time Based Key-Value Store | Medium | Solution | Test |
| 4 | Median of Two Sorted Arrays | Hard | Sol 1, Sol 2, Sol 3 | Test |
| 1235 | Maximum Profit in Job Scheduling | Hard | Sol 1, Sol 2, Sol 3 | Test |
| LC# | Problem | Level | Python Solution(s) | Unittest |
|---|---|---|---|---|
| 20 | Valid Parentheses | Easy | Solution | Test |
| 232 | Implement Queue using Stacks | Easy | Solution | Test |
| 496 | Next Greater Element I | Easy | Solution | Test |
| 150 | Evaluate Reverse Polish Notation | Medium | Solution | Test |
| 155 | Min Stack | Medium | Sol 1, Sol 2, Sol 3 | Test |
| 439 | Ternary Expression Parser | Medium | Solution | Test |
| 456 | 132 Pattern | Medium | Sol 1, Sol 2 | Test |
| 42 | Trapping Rain Water | Hard | Sol 1, Sol 2, Sol 3 | Test |
| 84 | Largest Rectangle in Histogram | Hard | Solution | Test |
| 224 | Basic Calculator | Hard | Sol 1, Sol 2, Sol 3 | Test |
| LC# | Problem | Level | Python Solution(s) | Unittest |
|---|---|---|---|---|
| 232 | Implement Queue using Stacks | Easy | Solution | Test |
| 146 | LRU Cache | Medium | Solution | Test |
| 155 | Min Stack | Medium | Sol 1, Sol 2, Sol 3 | Test |
| 208 | Implement Trie (Prefix Tree) | Medium | Solution | Test |
| 348 | Design Tic-Tac-Toe | Medium | Solution | Test |
| 981 | Time Based Key-Value Store | Medium | Solution | Test |
| 1396 | Design Underground System | Medium | Sol 1, Sol 2 | Test |
| 1429 | First Unique Number | Medium | Sol 1, Sol 2 | Test |
| 295 | Find Median from Data Stream | Hard | Solution | Test |
| 297 | Serialize and Deserialize Binary Tree | Hard | Solution | Test |
| 588 | Design In-Memory File System | Hard | Sol 1, Sol 2, Sol 3 | Test |
| LC# | Problem | Level | Python Solution(s) | Unittest |
|---|---|---|---|---|
| 125 | Valid Palindrome | Easy | Solution | Test |
| 141 | Linked List Cycle | Easy | Solution | Test |
| 202 | Happy Number | Easy | Sol 1, Sol 2 | Test |
| 234 | Palindrome Linked List | Easy | Sol 1, Sol 2 | Test |
| 876 | Middle of the Linked List | Easy | Solution | Test |
| 11 | Container With Most Water | Medium | Solution | Test |
| 15 | 3Sum | Medium | Sol 1, Sol 2 | Test |
| 19 | Remove Nth Node From End of List | Medium | Sol 1, Sol 2 | Test |
| 75 | Sort Colors | Medium | Solution | Test |
| 556 | Next Greater Element III | Medium | Solution | Test |
| 42 | Trapping Rain Water | Hard | Sol 1, Sol 2, Sol 3 | Test |
| 1537 | Get The Maximum Score | Hard | Solution | Test |
| LC# | Problem | Level | Python Solution(s) | Unittest |
|---|---|---|---|---|
| 409 | Longest Palindrome | Easy | Solution | Test |
| 11 | Container With Most Water | Medium | Solution | Test |
| 277 | Find the Celebrity | Medium | Solution | Test |
| 621 | Task Scheduler | Medium | Solution | Test |
| 1029 | Two City Scheduling | Medium | Solution | Test |
| 1537 | Get The Maximum Score | Hard | Solution | Test |
| LC# | Problem | Level | Python Solution(s) | Unittest |
|---|---|---|---|---|
| 67 | Add Binary | Easy | Solution | Test |
| 202 | Happy Number | Easy | Sol 1, Sol 2 | Test |
| 263 | Ugly Number | Easy | Solution | Test |
| 268 | Missing Number | Easy | Sol 1, Sol 2, Sol 3 | Test |
| 422 | Valid Word Square | Easy | Solution | Test |
| 1056 | Confusing Number | Easy | Solution | Test |
| 1228 | Missing Number In Arithmetic Progression | Easy | Sol 1, Sol 2 | Test |
| 7 | Reverse Interger | Medium | Solution | Test |
| 29 | Divide Two Integers | Medium | Sol 1, Sol 2 | Test |
| 70 | Climbing Stairs | Medium | Sol 1, Sol 2, Sol 3 | Test |
| 877 | Stone Game | Medium | Solution | Test |
| 224 | Basic Calculator | Hard | Sol 1, Sol 2, Sol 3 | Test |
| LC# | Problem | Level | Python Solution(s) | Unittest |
|---|---|---|---|---|
| 67 | Add Binary | Easy | Solution | Test |
| 29 | Divide Two Integers | Medium | Sol 1, Sol 2 | Test |
| LC# | Problem | Level | Python Solution(s) | Unittest |
|---|---|---|---|---|
| 264 | Ugly Number II | Medium | Sol 1, Sol 2 | Test |
| 621 | Task Scheduler | Medium | Solution | Test |
| 973 | K Closest Points to Origin | Medium | Sol 1, Sol 2 | Test |
| 1135 | Connecting Cities With Minimum Cost | Medium | Sol 1, Sol 2 | Test |
| 23 | Merge k Sorted Lists | Hard | Sol 1, Sol 2 | Test |
| 295 | Find Median from Data Stream | Hard | Solution | Test |
| LC# | Problem | Level | Python Solution(s) | Unittest |
|---|---|---|---|---|
| 733 | Flood Fill | Easy | Sol 1, Sol 2 | Test |
| 200 | Number of Islands | Medium | Sol 1, Sol 2, Sol 3 | Test |
| 207 | Course Schedule | Medium | Sol 1, Sol 2 | Test |
| 277 | Find the Celebrity | Medium | Solution | Test |
| 310 | Minimum Height Trees | Medium | Sol 1, Sol 2 | Test |
| 490 | The Maze | Medium | Sol 1, Sol 2 | Test |
| 721 | Accounts Merge | Medium | Sol 1, Sol 2, Sol 3 | Test |
| 994 | Rotting Oranges | Medium | Solution | Test |
| 1135 | Connecting Cities With Minimum Cost | Medium | Sol 1, Sol 2 | Test |
| 1466 | Reorder Routes to Make All Paths Lead to the City Zero | Medium | Sol 1, Sol 2 | Test |
| 127 | Word Ladder | Hard | Solution | Test |
| 269 | Alien Dictionary | Hard | Sol 1, Sol 2 | Test |
| 2050 | Parallel Courses III | Hard | Sol 1, Sol 2 | Test |
| LC# | Problem | Level | Python Solution(s) | Unittest |
|---|---|---|---|---|
| 207 | Course Schedule | Medium | Sol 1, Sol 2 | Test |
| 310 | Minimum Height Trees | Medium | Sol 1, Sol 2 | Test |
| 269 | Alien Dictionary | Hard | Sol 1, Sol 2 | Test |
| 2050 | Parallel Courses III | Hard | Sol 1, Sol 2 | Test |
| LC# | Problem | Level | Python Solution(s) | Unittest |
|---|---|---|---|---|
| 14 | Longest Common Prefix | Easy | Sol 1, Sol 2 | Test |
| 20 | Valid Parentheses | Easy | Solution | Test |
| 67 | Add Binary | Easy | Solution | Test |
| 125 | Valid Palindrome | Easy | Solution | Test |
| 242 | Valid Anagram | Easy | Solution | Test |
| 266 | Palindrome Permutation | Easy | Solution | Test |
| 383 | Ransom Note | Easy | Solution | Test |
| 409 | Longest Palindrome | Easy | Solution | Test |
| 5 | Longest Palindromic Substring | Medium | Sol 1, Sol 2 | Test |
| 8 | String to Integer (atoi) | Medium | Solution | Test |
| 139 | Word Break | Medium | Sol 1, Sol 2 | Test |
| 208 | Implement Trie (Prefix Tree) | Medium | Solution | Test |
| 247 | Strobogrammatic Number II | Medium | Solution | Test |
| 438 | Find All Anagrams in a String | Medium | Solution | Test |
| 439 | Ternary Expression Parser | Medium | Solution | Test |
| 556 | Next Greater Element III | Medium | Solution | Test |
| 76 | Minimum Window Substring | Hard | Solution | Test |
| 224 | Basic Calculator | Hard | Sol 1, Sol 2, Sol 3 | Test |
| LC# | Problem | Level | Python Solution(s) | Unittest |
|---|---|---|---|---|
| 438 | Find All Anagrams in a String | Medium | Solution | Test |
| 487 | Max Consecutive Ones II | Medium | Sol 1, Sol 2 | Test |
| 76 | Minimum Window Substring | Hard | Solution | Test |
| LC# | Problem | Level | Python Solution(s) | Unittest |
|---|---|---|---|---|
| 21 | Merge Two Sorted Lists | Easy | Sol 1, Sol 2 | Test |
| 141 | Linked List Cycle | Easy | Solution | Test |
| 206 | Reverse Linked List | Easy | Sol 1, Sol 2 | Test |
| 234 | Palindrome Linked List | Easy | Sol 1, Sol 2 | Test |
| 876 | Middle of the Linked List | Easy | Solution | Test |
| 1474 | Delete N Nodes After M Nodes of a Linked List | Easy | Solution | Test |
| 19 | Remove Nth Node From End of List | Medium | Sol 1, Sol 2 | Test |
| 146 | LRU Cache | Medium | Solution | Test |
| 1429 | First Unique Number | Medium | Sol 1, Sol 2 | Test |
| 23 | Merge k Sorted Lists | Hard | Sol 1, Sol 2 | Test |
| LC# | Problem | Level | Python Solution(s) | Unittest |
|---|---|---|---|---|
| 21 | Merge Two Sorted Lists | Easy | Sol 1, Sol 2 | Test |
| 206 | Reverse Linked List | Easy | Sol 1, Sol 2 | Test |
| 270 | Closest Binary Search Tree Value | Easy | Sol 1, Sol 2 | Test |
| 236 | Lowest Common Ancestor of a Binary Tree | Medium | Sol 1, Sol 2 | Test |
| 247 | Strobogrammatic Number II | Medium | Solution | Test |
| LC# | Problem | Level | Python Solution(s) | Unittest |
|---|---|---|---|---|
| 17 | Letter Combinations of a Phone Number | Medium | Sol 1, Sol 2 | Test |
| 39 | Combination Sum | Medium | Sol 1, Sol 2 | Test |
| 46 | Permutations | Medium | Sol 1, Sol 2 | Test |
| 78 | Subsets | Medium | Sol 1, Sol 2 | Test |
| 79 | Word Search | Medium | Sol 1, Sol 2, Sol 3 | Test |
| 490 | The Maze | Medium | Sol 1, Sol 2 | Test |
| LC# | Problem | Level | Python Solution(s) | Unittest |
|---|---|---|---|---|
| 268 | Missing Number | Easy | Sol 1, Sol 2, Sol 3 | Test |
| 56 | Merge Intervals | Medium | Solution | Test |
| 75 | Sort Colors | Medium | Solution | Test |
| 368 | Largest Divisible Subset | Medium | Sol 1, Sol 2 | Test |
| 973 | K Closest Points to Origin | Medium | Sol 1, Sol 2 | Test |
| 1029 | Two City Scheduling | Medium | Solution | Test |
| 1135 | Connecting Cities With Minimum Cost | Medium | Sol 1, Sol 2 | Test |
| 23 | Merge k Sorted Lists | Hard | Sol 1, Sol 2 | Test |
| 1235 | Maximum Profit in Job Scheduling | Hard | Sol 1, Sol 2, Sol 3 | Test |
| LC# | Problem | Level | Python Solution(s) | Unittest |
|---|---|---|---|---|
| 200 | Number of Islands | Medium | Sol 1, Sol 2, Sol 3 | Test |
| 721 | Accounts Merge | Medium | Sol 1, Sol 2, Sol 3 | Test |
| 1135 | Connecting Cities With Minimum Cost | Medium | Sol 1, Sol 2 | Test |
| LC# | Problem | Level | Python Solution(s) | Unittest |
|---|---|---|---|---|
| 1135 | Connecting Cities With Minimum Cost | Medium | Sol 1, Sol 2 | Test |
| LC# | Problem | Level | Python Solution(s) | Unittest |
|---|---|---|---|---|
| 14 | Longest Common Prefix | Easy | Sol 1, Sol 2 | Test |
| 208 | Implement Trie (Prefix Tree) | Medium | Solution | Test |
| 588 | Design In-Memory File System | Hard | Sol 1, Sol 2, Sol 3 | Test |
| LC# | Problem | Level | Python Solution(s) | Unittest |
|---|---|---|---|---|
| 238 | Product of Array Except Self | Medium | Sol 1, Sol 2 | Test |
| 487 | Max Consecutive Ones II | Medium | Sol 1, Sol 2 | Test |
| 560 | Subarray Sum Equals K | Medium | Solution | Test |
| 1537 | Get The Maximum Score | Hard | Solution | Test |
| LC# | Problem | Level | Python Solution(s) | Unittest |
|---|---|---|---|---|
| 105 | Construct Binary Tree from Preorder and Inorder Traversal | Medium | Sol 1, Sol 2 | Test |
| 4 | Median of Two Sorted Arrays | Hard | Sol 1, Sol 2, Sol 3 | Test |
| 23 | Merge k Sorted Lists | Hard | Sol 1, Sol 2 | Test |
| LC# | Problem | Level | Python Solution(s) | Unittest |
|---|---|---|---|---|
| 422 | Valid Word Square | Easy | Solution | Test |
| 733 | Flood Fill | Easy | Sol 1, Sol 2 | Test |
| 54 | Spiral Matrix | Medium | Solution | Test |
| 62 | Unique Paths | Medium | Sol 1, Sol 2 | Test |
| 79 | Word Search | Medium | Sol 1, Sol 2, Sol 3 | Test |
| 200 | Number of Islands | Medium | Sol 1, Sol 2, Sol 3 | Test |
| 348 | Design Tic-Tac-Toe | Medium | Solution | Test |
| 490 | The Maze | Medium | Sol 1, Sol 2 | Test |
| 542 | 01 Matrix | Medium | Sol 1, Sol 2 | Test |
| 994 | Rotting Oranges | Medium | Solution | Test |
| LC# | Problem | Level | Python Solution(s) | Unittest |
|---|---|---|---|---|
| 270 | Closest Binary Search Tree Value | Easy | Sol 1, Sol 2 | Test |
| 98 | Validate Binary Search Tree | Medium | Sol 1, Sol 2, Sol 3 | Test |
| 230 | Kth Smallest Element in a BST | Medium | Sol 1, Sol 2 | Test |
| LC# | Problem | Level | Python Solution(s) | Unittest |
|---|---|---|---|---|
| 232 | Implement Queue using Stacks | Easy | Solution | Test |
| 1429 | First Unique Number | Medium | Sol 1, Sol 2 | Test |
| LC# | Problem | Level | Python Solution(s) | Unittest |
|---|---|---|---|---|
| 169 | Majority Element | Easy | Solution | Test |
| LC# | Problem | Level | Python Solution(s) | Unittest |
|---|---|---|---|---|
| 252 | Meeting Rooms | Easy | Solution | Test |
Each solved problem have a unittest/ folder.
To locate the Python test script, click on the test link of the problem.
To run the test script, add the below code and Run the _unittest.py:
if __name__ == '__main__':
unittest.main()
You can also add more test cases by appending to the class Test(unittest.TestCase):
For example:
def test_your_test_case(self):
input_nums = [3,3]
target = 6
expected_output = {0,1}
output = set(self.s.twoSum(input_nums, target))
self.assertEqual(output, expected_output)
Each problem is already equipped with helpers functions to execute the test cases without additional dependencies.
Please follow the format of the existing test cases when creating your own.
Happy coding :)