Python solution to Leetcode Questions.
This is a very good platform to learn best practices of python coding.
I am compiling solutions to some questions as I solve and have tried to include as many comments as possible for easy understanding.
(Tip: The best way I think is to print and see what exactly is being executed !)
Just keep Practicing !
# | Title | Solutions | Difficulty | Tag | Remarks |
---|---|---|---|---|---|
1 | Two Sum | Solution | Easy | hashmap | Am,Ad,G,A,M,Bl,U... |
2 | Add Two Numbers | Solution | Medium | Linked List | Am,Ad,Bl,A,M,G,F,U... |
21 | Merge Two Sorted Lists | Solution | Easy | LinkedList | 04Jan21 challenge |
35 | Search Insert Position | Solution | Easy | List | June10 challenge |
68 | Text Justification | Solution | Hard | String | I,G,K,Tl,U,L,R,F,M,A,E |
77 | Combinations | Solution | Medium | Backtracking | |
88 | Merge Sorted Array | Solution | Easy | two-pointer | . |
104 | Maximum Depth of Binary Tree | Solution | Easy | Tree DFS Recursion and iterative | . |
118 | Pascal's Triangle | Solution | Easy | String, DP | Am,M,A,Ad,U Y |
120 | Triangle | Solution | Medium | DP | 21Apr21 challenge |
128 | Longest Consecutive Sequence | Solution | Medium | List, Set | G,M,A,F,Ad,T,Q |
141 | Linked List Cycle | Solution | Easy | two-pointer | . |
167 | Two Sum II - Input array is sorted | Solution | Easy | two-pointer | . |
175 | Combine Two Tables | Solution | Easy | SQL | Ad,Am,Bl,A |
176 | Second Highest Salary | Solution | Easy | SQL | Am,A |
177 | Nth Highest Salary | Solution | Easy | SQL | Am,Bl,Ad,A,G,Or |
181 | Employees Earning More Than Their Managers | Solution | Easy | SQL | Am,A |
184 | Department Highest Salary | Solution | Medium | SQL | Am,A |
185 | Department Top Three Salaries | Solution | Hard | SQL | Am,U,E,F |
200 | Number of Islands | Solution | Medium | DFS,Matrix | Am,M,B,G,F,L,A,O |
226 | Invert Binary Tree | Solution | Easy | Binary Search Tree | June01 challenge |
231 | Power of Two | Solution | Easy | June08 challenge | |
232 | Implement Queue using Stacks | Solution | Easy | Am,M,A,GS | |
237 | Delete Node in a Linked List | Solution | Easy | Linked List | 02June20 challenge |
242 | Valid Anagram | Solution | Easy | List | Bl,G,M,U,Am,A,W,J |
243 | Shortest Word Distance | Solution | Easy | List | L,A,GS,M,U,SF,DD |
290 | Word Pattern | Solution | Easy | string,dictionary | . |
344 | Reverse String | Solution | Easy | List | June04 challenge |
350 | Intersection of Two Arrays II | Solution | Easy | two-pointer | . |
359 | Logger Rate Limiter | Solution | Easy | hash map | . |
366 | Find Leaves of Binary Tree | Solution | Medium | Recursion | 03Jul21 challenge |
377 | Combination Sum IV | Solution | Medium | DP | 19Apr21 challenge |
392 | Is Subsequence | Solution | Easy | List | June09 challenge |
406 | Queue Reconstruction by Height | Solution | Medium | List | 06June20 challenge |
438 | Find All Anagrams in a String | Solution | Medium | Sliding Window | M,Am,F,P,G |
451 | Sort Characters By Frequency | Solution | Medium | String,Hash Table | |
474 | Ones and Zeroes | Solution | Medium | DP | 03Apr21 challenge |
509 | Not Boring Movies | Solution | Easy | hash map | 15Apr21 challenge |
518 | Coin Change 2 | Solution | Medium | Dynamic Programming | June07 challenge |
594 | Longest Harmonious Subsequence | Solution | Easy | Hash Table | |
595 | Big Countries | Solution | Easy | SQL | |
605 | Can Place Flowers | Solution | Easy | String | L,F |
620 | Fibonacci Number | Solution | Easy | ||
655 | Print Binary Tree | Solution | Medium | Binary Tree | |
690 | Employee Importance | Solution | Easy | Tree | G,A |
700 | Search in a Binary Search Tree | Solution | Easy | Binary Search Tree | June15 challenge |
703 | Kth Largest Element in a Stream | Solution | Easy | Heapq | Am,F |
796 | Rotate String | Solution | Easy | String | |
973 | K Closest Points to Origin | Solution | Medium | Lists, Hash Table | |
938 | Range Sum of BST | Solution | Easy | Tree DFS Iterative | |
1029 | Two City Scheduling | Solution | Easy | List Greedy | June03 challenge |
1179 | Reformat Department Table | Solution | Easy | SQL | |
1200 | Minimum Absolute Difference | Solution | Easy | Hash Table | |
1207 | Unique Number of Occurrences | Solution | Easy | Hash Table | |
1209 | Remove All Adjacent Duplicates in String II | Solution | Easy | stack | 16Apr21 challenge |
1436 | Destination City | Solution | Easy | List | |
1762 | Buildings with an ocean view | Solution | Medium | List | F |