LeetCode Solutions in Python¶
A collection of LeetCode solutions in Python, organised by difficulty, with notes on common patterns and data structures.
26Easy
75Medium
1Hard
NeetCode 250 · 82 / 250¶
Arrays & Hashing · 5 / 22 (23%)
- Best Time to Buy And Sell Stock II
- Concatenation of Array
- Contains Duplicate
- Design HashMap
- Design HashSet
- Encode and Decode Strings
- First Missing Positive
- Group Anagrams
- Longest Common Prefix
- Longest Consecutive Sequence
- Majority Element
- Majority Element II
- Product of Array Except Self
- Range Sum Query 2D Immutable
- Remove Element
- Sort an Array
- Sort Colors
- Subarray Sum Equals K
- Top K Frequent Elements
- Two Sum
- Valid Anagram
- Valid Sudoku
Two Pointers · 3 / 13 (23%)
- 3Sum
- 4Sum
- Boats to Save People
- Container With Most Water
- Merge Sorted Array
- Merge Strings Alternately
- Remove Duplicates From Sorted Array
- Reverse String
- Rotate Array
- Trapping Rain Water
- Two Sum II Input Array Is Sorted
- Valid Palindrome
- Valid Palindrome II
Sliding Window · 3 / 9 (33%)
- Best Time to Buy And Sell Stock
- Contains Duplicate II
- Find K Closest Elements
- Longest Repeating Character Replacement
- Longest Substring Without Repeating Characters
- Minimum Size Subarray Sum
- Minimum Window Substring
- Permutation In String
- Sliding Window Maximum
Stack · 4 / 14 (29%)
- Asteroid Collision
- Baseball Game
- Car Fleet
- Daily Temperatures
- Decode String
- Evaluate Reverse Polish Notation
- Implement Queue using Stacks
- Implement Stack Using Queues
- Largest Rectangle In Histogram
- Maximum Frequency Stack
- Min Stack
- Online Stock Span
- Simplify Path
- Valid Parentheses
Binary Search · 7 / 14 (50%)
- Binary Search
- Capacity to Ship Packages Within D Days
- Find in Mountain Array
- Find Minimum In Rotated Sorted Array
- Guess Number Higher Or Lower
- Koko Eating Bananas
- Median of Two Sorted Arrays
- Search a 2D Matrix
- Search In Rotated Sorted Array
- Search In Rotated Sorted Array II
- Search Insert Position
- Split Array Largest Sum
- Sqrt(x)
- Time Based Key Value Store
Linked List · 7 / 14 (50%)
- Add Two Numbers
- Copy List With Random Pointer
- Design Circular Queue
- Find The Duplicate Number
- LFU Cache
- Linked List Cycle
- LRU Cache
- Merge K Sorted Lists
- Merge Two Sorted Lists
- Remove Nth Node From End of List
- Reorder List
- Reverse Linked List
- Reverse Linked List II
- Reverse Nodes In K Group
Trees · 10 / 23 (43%)
- Balanced Binary Tree
- Binary Tree Inorder Traversal
- Binary Tree Level Order Traversal
- Binary Tree Maximum Path Sum
- Binary Tree Postorder Traversal
- Binary Tree Preorder Traversal
- Binary Tree Right Side View
- Construct Binary Tree From Preorder And Inorder Traversal
- Construct Quad Tree
- Count Good Nodes In Binary Tree
- Delete Leaves With a Given Value
- Delete Node in a BST
- Diameter of Binary Tree
- House Robber III
- Insert into a Binary Search Tree
- Invert Binary Tree
- Kth Smallest Element In a Bst
- Lowest Common Ancestor of a Binary Search Tree
- Maximum Depth of Binary Tree
- Same Tree
- Serialize And Deserialize Binary Tree
- Subtree of Another Tree
- Validate Binary Search Tree
Tries · 0 / 4 (0%)
- Design Add And Search Words Data Structure
- Extra Characters in a String
- Implement Trie Prefix Tree
- Word Search II
Heap / Priority Queue · 4 / 12 (33%)
- Car Pooling
- Design Twitter
- Find Median From Data Stream
- IPO
- K Closest Points to Origin
- Kth Largest Element In a Stream
- Kth Largest Element In An Array
- Last Stone Weight
- Longest Happy String
- Reorganize String
- Single Threaded CPU
- Task Scheduler
Intervals · 5 / 7 (71%)
- Insert Interval
- Meeting Rooms
- Meeting Rooms II
- Meeting Rooms III
- Merge Intervals
- Minimum Interval to Include Each Query
- Non Overlapping Intervals
Greedy · 1 / 14 (7%)
- Candy
- Dota2 Senate
- Gas Station
- Hand of Straights
- Jump Game
- Jump Game II
- Jump Game VII
- Lemonade Change
- Longest Turbulent Subarray
- Maximum Subarray
- Maximum Sum Circular Subarray
- Merge Triplets to Form Target Triplet
- Partition Labels
- Valid Parenthesis String
Graphs · 9 / 21 (43%)
- Accounts Merge
- Clone Graph
- Course Schedule
- Course Schedule II
- Course Schedule IV
- Evaluate Division
- Find the Town Judge
- Graph Valid Tree
- Island Perimeter
- Max Area of Island
- Minimum Height Trees
- Number of Connected Components In An Undirected Graph
- Number of Islands
- Open The Lock
- Pacific Atlantic Water Flow
- Redundant Connection
- Rotting Oranges
- Surrounded Regions
- Verifying An Alien Dictionary
- Walls And Gates
- Word Ladder
Advanced Graphs · 3 / 10 (30%)
- Alien Dictionary
- Build a Matrix With Conditions
- Cheapest Flights Within K Stops
- Find Critical and Pseudo Critical Edges in Minimum Spanning Tree
- Greatest Common Divisor Traversal
- Min Cost to Connect All Points
- Network Delay Time
- Path with Minimum Effort
- Reconstruct Itinerary
- Swim In Rising Water
Backtracking · 5 / 17 (29%)
- Combination Sum
- Combination Sum II
- Combinations
- Generate Parentheses
- Letter Combinations of a Phone Number
- Matchsticks to Square
- N Queens
- N Queens II
- Palindrome Partitioning
- Partition to K Equal Sum Subsets
- Permutations
- Permutations II
- Subsets
- Subsets II
- Sum of All Subsets XOR Total
- Word Break II
- Word Search
1-D Dynamic Programming · 6 / 17 (35%)
- Climbing Stairs
- Coin Change
- Combination Sum IV
- Decode Ways
- House Robber
- House Robber II
- Integer Break
- Longest Increasing Subsequence
- Longest Palindromic Substring
- Maximum Product Subarray
- Min Cost Climbing Stairs
- N-th Tribonacci Number
- Palindromic Substrings
- Partition Equal Subset Sum
- Perfect Squares
- Stone Game III
- Word Break
2-D Dynamic Programming · 3 / 16 (19%)
- Best Time to Buy And Sell Stock With Cooldown
- Burst Balloons
- Coin Change II
- Distinct Subsequences
- Edit Distance
- Interleaving String
- Last Stone Weight II
- Longest Common Subsequence
- Longest Increasing Path In a Matrix
- Minimum Path Sum
- Regular Expression Matching
- Stone Game
- Stone Game II
- Target Sum
- Unique Paths
- Unique Paths II
Bit Manipulation · 3 / 10 (30%)
- Add Binary
- Bitwise AND of Numbers Range
- Counting Bits
- Minimum Array End
- Missing Number
- Number of 1 Bits
- Reverse Bits
- Reverse Integer
- Single Number
- Sum of Two Integers
Math & Geometry · 2 / 13 (15%)
- Detect Squares
- Excel Sheet Column Title
- Greatest Common Divisor of Strings
- Happy Number
- Insert Greatest Common Divisors in Linked List
- Multiply Strings
- Plus One
- Pow(x, n)
- Roman to Integer
- Rotate Image
- Set Matrix Zeroes
- Spiral Matrix
- Transpose Matrix
Other Solutions · 20¶
Show 20 solutions
| File | Difficulty | Inferred name |
|---|---|---|
29_divide_two_integers.py |
Medium | Divide Two Integers |
34_find_first_and_last_position_of_element_in_sorted_array.py |
Medium | Find First And Last Position Of Element In Sorted Array |
116_populating_next_right_pointers_in_each_node.py |
Medium | Populating Next Right Pointers In Each Node |
137_single_number_2.py |
Medium | Single Number 2 |
201_range_bitwise_and.py |
Medium | Range Bitwise And |
202_is_happy.py |
Easy | Is Happy |
319_BulbSwitcher.py |
Medium | Bulbswitcher |
496_next_greater_element.py |
Easy | Next Greater Element |
547_number_of_province.py |
Medium | Number Of Province |
637_average_of_levels_in_binary_tree.py |
Easy | Average Of Levels In Binary Tree |
643_maximum_average_subarray.py |
Easy | Maximum Average Subarray |
670_maximum_swap.py |
Medium | Maximum Swap |
740_delete_and_earn.py |
Medium | Delete And Earn |
797_all_path_from_source_to_target.py |
Medium | All Path From Source To Target |
1090_shortest_path_in_binary_matrix.py |
Medium | Shortest Path In Binary Matrix |
1123_lowest_common_anchestor_of_deepest_leaves.py |
Medium | Lowest Common Anchestor Of Deepest Leaves |
1710_maximum_units_on_truck.py |
Easy | Maximum Units On Truck |
1942_the_number_of_the_smallest_unoccupide_chair.py |
Medium | The Number Of The Smallest Unoccupide Chair |
1971_find_if_path_exists_in_graph.py |
Easy | Find If Path Exists In Graph |
2483_minimum_penalty_for_a_shop.py |
Medium | Minimum Penalty For A Shop |
Structure¶
- Common Patterns — theory notes and cheat sheets for the most frequent algorithmic patterns
- Cheat Sheet — quick-reference card covering complexity, patterns, and idioms
- API Reference — auto-generated documentation from the source code