Skip to content

My solutions in C++, Python and Rust for problems on NeetCode.io

License

Notifications You must be signed in to change notification settings

mdmzfzl/NeetCode-Solutions

Repository files navigation

What is NeetCode 150?

Neetcode 150 is a curated list of 150 LeetCode problems designed to cover all topics in data structures. It is an invaluable resource to study for LeetCode-style interviews you might enounter at FAANG and other big tech companies. There are several categories of questions and inside each category are easy, medium, and hard questions.

Creator's original repository and website.

Below is a list of my solutions for all the problems in C++ and Python.

To contribute, see here.

Arrays & Hashing

LeetCode ID Difficulty Problem Solution
217 Easy Contains Duplicate C++Python
242 Easy Valid Anagram C++Python
1 Easy Two Sum C++Python
49 Medium Group Anagrams C++Python
347 Medium Top K Frequent Elements C++Python
238 Medium Product of Array Except Self C++Python
36 Medium Valid Sudoku C++Python
271 Medium Encode and Decode Strings C++Python
128 Medium Longest Consecutive Sequence C++Python

Two Pointers

LeetCode ID Difficulty Problem Solution
125 Easy Valid Palindrome C++Python
167 Medium Two Sum II C++Python
15 Medium 3Sum C++Python
11 Medium Container with Most Water C++Python
42 Hard Trapping Rain Water C++Python

Sliding Window

LeetCode ID Difficulty Problem Solution
121 Easy Best Time to Buy & Sell Stock C++Python
3 Medium Longest Substring Without Repeating Characters C++Python
424 Medium Longest Repeating Character Replacement C++Python
567 Medium Permutation in String C++Python
76 Hard Minimum Window Substring C++Python
239 Hard Sliding Window Maximum C++Python

Stack

LeetCode ID Difficulty Problem Solution
20 Easy Valid Parentheses C++Python
155 Medium Min Stack C++Python
150 Medium Evaluate Reverse Polish Notation C++Python
22 Medium Generate Parentheses C++Python
739 Medium Daily Temperatures C++Python
853 Medium Car Fleet C++Python
84 Hard Largest Rectangle in Histogram C++Python

Binary Search

LeetCode ID Difficulty Problem Solution
704 Easy Binary Search C++Python
74 Medium Search a 2D Matrix C++Python
875 Medium Koko Eating Bananas C++Python
33 Medium Search in Rotated Sorted Array C++Python
153 Medium Find Minimum in Rotated Sorted Array C++Python
981 Medium Time Based Key-Value Store C++Python
4 Hard Median of Two Sorted Arrays C++Python

Linked List

LeetCode ID Difficulty Problem Solution
206 Easy Reverse Linked List C++Python
21 Easy Merge Two Sorted Lists C++Python
143 Medium Reorder List C++Python
19 Medium Remove Nth Node From End of List C++Python
141 Easy Copy List with Random Pointer C++Python
2 Medium Add Two Numbers C++Python
141 Easy Linked List Cycle C++Python
287 Medium Find the Duplicate Number C++Python
146 Medium LRU Cache C++Python
23 Hard Merge k Sorted Lists C++Python
25 Hard Reverse Nodes in k-Group C++Python

Trees

LeetCode ID Difficulty Problem Solution
226 Easy Invert Binary Tree C++Python
104 Easy Maximum Depth of Binary Tree C++Python
543 Easy Diameter of Binary Tree C++Python
110 Easy Balanced Binary Tree C++Python
100 Easy Same Tree C++Python
572 Easy Subtree Of Another Tree C++Python
235 Medium Lowest Common Ancestor Of A Binary Search Tree C++Python
102 Medium Binary Tree Level Order Traversal C++Python
199 Medium Binary Tree Right Side View C++Python
1448 Medium Count Good Nodes in Binary Tree C++Python
98 Medium Validate Binary Search Tree C++Python
230 Medium Kth Smallest Element in a BST C++Python
105 Medium Construct Binary Tree from Preorder and Inorder Traversal C++Python
124 Hard Binary Tree Maximum Path Sum C++Python
297 Hard Serialize and Deserialize Binary Tree C++Python

Tries

LeetCode ID Difficulty Problem Solution
208 Medium Implement Trie (Prefix Tree) C++Python
211 Medium Design Add and Search Words Data Structure C++Python
212 Hard Word Search II C++Python

Heap / Priority Queue

LeetCode ID Difficulty Problem Solution
703 Easy Kth Largest Element in a Stream C++Python
1046 Easy Last Stone Weight C++Python
973 Medium K Closest Points to Origin C++Python
215 Medium Kth Largest Element in an Array C++Python
621 Medium Task Scheduler C++Python
355 Medium Design Twitter C++Python
295 Hard Find Median from Data Stream C++Python

Backtracking

LeetCode ID Difficulty Problem Solution
78 Medium Subsets C++Python
39 Medium Combination Sum C++Python
46 Medium Permutations C++Python
90 Medium Subsets II C++Python
40 Medium Combination Sum II C++Python
79 Medium Word Search C++Python
131 Medium Palindrome Partitioning C++Python
17 Medium Letter Combinations of a Phone Number C++Python
51 Hard N-Queens C++Python

Graphs

LeetCode ID Difficulty Problem Solution
200 Medium Number of Islands C++Python
133 Medium Clone Graph C++Python
695 Medium Max Area of Island C++Python
417 Medium Pacific Atlantic Water Flow C++Python
130 Medium Surrounded Regions C++Python
994 Medium Rotting Oranges C++Python
286 Medium Walls and Gates C++Python
207 Medium Course Schedule C++Python
210 Medium Course Schedule II C++Python
684 Medium Redundant Connection C++Python
323 Medium Number of Connected Components In An Undirected Graph C++Python
261 Medium Graph Valid Tree C++Python
127 Hard Word Ladder C++Python

Advanced Graphs

LeetCode ID Difficulty Problem Solution
332 Hard Reconstruct Itinerary C++Python
1584 Medium Min Cost to Connect All Points C++Python
743 Medium Network Delay Time C++Python
778 Hard Swim in Rising Water C++Python
269 Hard Alien Dictionary C++Python
787 Medium Cheapest Flights Within K Stops C++Python

1-D Dynamic Programming

LeetCode ID Difficulty Problem Solution
70 Easy Climbing Stairs C++Python
746 Easy Min Cost Climbing Stairs C++Python
198 Medium House Robber C++Python
213 Medium House Robber II C++Python
5 Medium Longest Palindromic Substring C++Python
647 Medium Palindromic Substrings C++Python
91 Medium Decode Ways C++Python
322 Medium Coin Change C++Python
152 Medium Maximum Product Subarray C++Python
139 Medium Word Break C++Python
300 Medium Longest Increasing Subsequence C++Python
416 Medium Partition Equal Subset Sum C++Python

2-D Dynamic Programing

LeetCode ID Difficulty Problem Solution
62 Medium Unique Paths C++Python
1143 Medium Longest Common Subsequence C++Python
309 Medium Best Time to Buy and Sell Stock with Cooldown C++Python
518 Medium Coin Change II C++Python
494 Medium Target Sum C++Python
97 Medium Interleaving String C++Python
329 Hard Longest Increasing Path in a Matrix C++Python
115 Hard Distinct Subsequences C++Python
72 Hard Edit Distance C++Python
312 Hard Burst Balloons C++Python
10 Hard Regular Expression Matching C++Python

Greedy

LeetCode ID Difficulty Problem Solution
53 Medium Maximum Subarray C++Python
55 Medium Jump Game C++Python
45 Medium Jump Game II C++Python
134 Medium Gas Station C++Python
846 Medium Hand of Straights C++Python
1899 Medium Merge Triplets to Form Target Triplet C++Python
763 Medium Partition Labels C++Python
678 Medium Valid Parenthesis String C++Python

Intervals

LeetCode ID Difficulty Problem Solution
57 Medium Insert Interval C++Python
56 Medium Merge Intervals C++Python
435 Medium Non-overlapping Intervals C++Python
252 Easy Meeting Rooms C++Python
253 Medium Meeting Rooms II C++Python
1851 Hard Minimum Interval to Include Each Query C++Python

Math & Geometry

LeetCode ID Difficulty Problem Solution
48 Medium Rotate Image C++Python
54 Medium Spiral Matrix C++Python
73 Medium Set Matrix Zeroes C++Python
202 Easy Happy Number C++Python
66 Easy Plus One C++Python
50 Medium Pow(x, n) C++Python
43 Medium Multiply Strings C++Python
2013 Medium Detect Squares C++Python

Bit Manipulation

LeetCode ID Difficulty Problem Solution
136 Easy Single Number C++Python
191 Easy Number of 1 Bits C++Python
338 Easy Counting Bits C++Python
190 Easy Reverse Bits C++Python
268 Easy Missing Number C++Python
371 Medium Sum of Two Integers C++Python
7 Medium Reverse Integer C++Python

Contributing

If you have a better solution, feel free to open a PR. Add a small summary of your solution with space and time complexities.

Guidelines

  • Make sure your code passes all the test cases on LeetCode for the problem it solves.
  • Write clean code that is easy to understand.
  • Give your PR a succinct and accurate title.