This repository contains solutions to the 150 essential Data Structures and Algorithms problems curated by the NeetCode platform. The problems are solved in Python and organized into separate folders, following the structured roadmap as seen on the NeetCode Roadmap. This roadmap covers a wide range of algorithmic topics commonly tested in technical interviews at top companies.
This repository is based on the NeetCode roadmap, covering the following core topics:
- Arrays & Hashing: Efficient manipulation and lookup of arrays.
- Two Pointers: Optimized algorithms for processing arrays and linked lists.
- Stack: Use of LIFO structures in various problem-solving scenarios.
- Sliding Window: Techniques for solving problems that require processing continuous subarrays.
- Binary Search: Classic and advanced search techniques over sorted data.
- Linked List: Manipulating nodes and solving problems related to linked lists.
- Trees: Solving problems using binary trees, binary search trees, and more.
- Tries: Efficient data structures for word and prefix problems.
- Backtracking: Recursion-based approaches for solving complex search problems.
- Heap / Priority Queue: Optimized data retrieval in constant time using heaps.
- Graphs: Fundamental and advanced graph algorithms for traversals and searches.
- Intervals: Problems based on overlapping intervals.
- Greedy Algorithms: Problem-solving strategies that involve making optimal choices at each step.
- 1D Dynamic Programming (1D DP): Solving problems using memoization or tabulation techniques.
- 2D Dynamic Programming (2D DP): Extending DP concepts to 2D structures.
- Bit Manipulation: Efficient problem-solving using bitwise operations.
- Math & Geometry: Problems involving mathematical reasoning and geometric properties.
The repository is organized into directories based on different problem categories. Each category corresponds to a section in the NeetCode roadmap. Inside each folder, you will find Python solutions for the respective problems, with problem names as filenames. Here's the directory structure:
├── Arrays & Hashing/
│ ├── contains-duplicate.py
│ ├── valid-anagram.py
│ ├── two-sum.py
│ ├── group-anagrams.py
│ ├── top-k-frequent-elements.py
│ └── product-of-array-except-self.py
├── Two Pointers/
│ ├── valid-palindrome.py
│ ├── two-sum-ii-input-array-is-sorted.py
│ ├── three-sum.py
│ ├── container-with-most-water.py
│ └── remove-nth-node-from-end-of-list.py
├── Stack/
│ ├── valid-parentheses.py
│ ├── min-stack.py
│ ├── evaluate-reverse-polish-notation.py
│ ├── generate-parentheses.py
│ └── daily-temperatures.py
├── Sliding Window/
│ ├── best-time-to-buy-and-sell-stock.py
│ ├── longest-substring-without-repeating-characters.py
│ ├── permutation-in-string.py
│ ├── minimum-window-substring.py
│ └── sliding-window-maximum.py
├── Binary Search/
│ ├── binary-search.py
│ ├── search-in-rotated-sorted-array.py
│ ├── find-minimum-in-rotated-sorted-array.py
│ ├── search-a-2d-matrix.py
│ └── find-median-from-data-stream.py
├── Linked List/
│ ├── reverse-linked-list.py
│ ├── merge-two-sorted-lists.py
│ ├── reorder-list.py
│ ├── remove-linked-list-elements.py
│ └── linked-list-cycle.py
├── Trees/
│ ├── maximum-depth-of-binary-tree.py
│ ├── same-tree.py
│ ├── invert-binary-tree.py
│ ├── binary-tree-level-order-traversal.py
│ ├── validate-binary-search-tree.py
│ ├── lowest-common-ancestor-of-a-binary-search-tree.py
│ └── serialize-and-deserialize-binary-tree.py
├── Tries/
│ ├── implement-trie-prefix-tree.py
│ ├── word-search-ii.py
│ └── design-add-and-search-words-data-structure.py
├── Backtracking/
│ ├── subsets.py
│ ├── combination-sum.py
│ ├── permutations.py
│ ├── word-search.py
│ └── palindrome-partitioning.py
├── Heap & Priority Queue/
│ ├── kth-largest-element-in-a-stream.py
│ ├── task-scheduler.py
│ ├── find-median-from-data-stream.py
│ └── merge-k-sorted-lists.py
├── Graphs/
│ ├── number-of-islands.py
│ ├── clone-graph.py
│ ├── course-schedule.py
│ ├── pacific-atlantic-water-flow.py
│ ├── number-of-connected-components-in-an-undirected-graph.py
│ └── graph-valid-tree.py
├── Intervals/
│ ├── insert-interval.py
│ ├── merge-intervals.py
│ ├── non-overlapping-intervals.py
│ └── meeting-rooms-ii.py
├── Greedy/
│ ├── jump-game.py
│ ├── maximum-subarray.py
│ ├── gas-station.py
│ └── candy.py
├── 1D Dynamic Programming/
│ ├── climb-stairs.py
│ ├── house-robber.py
│ ├── coin-change.py
│ ├── longest-increasing-subsequence.py
│ └── word-break.py
├── 2D Dynamic Programming/
│ ├── unique-paths.py
│ ├── longest-common-subsequence.py
│ ├── edit-distance.py
│ ├── maximal-square.py
│ └── dungeon-game.py
├── Bit Manipulation/
│ ├── single-number.py
│ ├── number-of-1-bits.py
│ ├── reverse-bits.py
│ ├── missing-number.py
│ └── sum-of-two-integers.py
├── Math & Geometry/
│ ├── rotate-image.py
│ ├── spiral-matrix.py
│ ├── set-matrix-zeroes.py
│ └── powx-n.py
For each problem in this repository, you'll find:
- Problem Description: A brief summary or link to the problem statement.
- Solution: The Python code that solves the problem, with an emphasis on clarity and efficiency.
- Time & Space Complexity: An analysis of the time and space complexity for each solution.
Contributions are welcome! If you'd like to improve a solution, add more explanations, or even introduce more test cases, feel free to open a pull request. Ensure your code follows the structure and clarity standards of the repository.