A comprehensive collection of solutions to the NeetCode 150 problem set, implemented in C#. This repository contains well-commented, optimized solutions with detailed explanations of algorithms, time/space complexity analysis, and problem-solving strategies.
This repository follows the NeetCode 150 curated list of essential coding interview problems. Each solution includes:
- ✅ Detailed inline comments explaining every step
- ⏱️ Time and space complexity analysis
- 📝 Problem description and examples
- 🎯 Key insights and algorithm explanations
- 💡 Edge cases and optimization notes
Total Problems Solved: 51/150
| Category | Total Problems | Problems Solved |
|---|---|---|
| Arrays & Hashing | 9 | 9 |
| Two Pointers | 5 | 5 |
| Sliding Window | 6 | 6 |
| Stack | 8 | 8 |
| Binary Search | 7 | 7 |
| Linked List | 6 | 6 |
| Trees | 15 | 0 |
| Tries | 3 | 0 |
| Heap / Priority Queue | 3 | 0 |
| Backtracking | 9 | 0 |
| Graphs | 13 | 0 |
| Advanced Graphs | 6 | 0 |
| 1-D Dynamic Programming | 12 | 0 |
| 2-D Dynamic Programming | 11 | 0 |
| Greedy | 8 | 0 |
| Intervals | 6 | 6 |
| Math & Geometry | 8 | 0 |
| Bit Manipulation | 7 | 0 |
| # | Problem | Difficulty | Solution | Topics |
|---|---|---|---|---|
| 1 | Contains Duplicate | 🟢 Easy | C# | Hash Set |
| 2 | Valid Anagram | 🟢 Easy | C# | Hash Map, Sorting |
| 3 | Two Sum | 🟢 Easy | C# | Hash Map |
| 4 | Group Anagrams | 🟡 Medium | C# | Hash Map, Sorting |
| 5 | Top K Frequent Elements | 🟡 Medium | C# | Bucket Sort, Heap |
| 6 | Encode and Decode Strings | 🟡 Medium | C# | String Manipulation |
| 7 | Product of Array Except Self | 🟡 Medium | C# | Prefix/Suffix Product |
| 8 | Valid Sudoku | 🟡 Medium | C# | Hash Set, Matrix |
| 9 | Longest Consecutive Sequence | 🟡 Medium | C# | Hash Set, Union Find |
Key Patterns:
- Hash Map for O(1) lookups
- Frequency counting and bucketing
- Array manipulation without division
| # | Problem | Difficulty | Solution | Topics |
|---|---|---|---|---|
| 10 | Valid Palindrome | 🟢 Easy | C# | Two Pointers, String |
| 11 | Two Sum II | 🟡 Medium | C# | Two Pointers, Binary Search |
| 12 | 3Sum | 🟡 Medium | C# | Two Pointers, Sorting |
| 13 | Container With Most Water | 🟡 Medium | C# | Two Pointers, Greedy |
| 14 | Trapping Rain Water | 🔴 Hard | C# | Two Pointers, Dynamic Programming |
Key Patterns:
- Opposite direction pointers
- Sorted array optimization
- Greedy decision making
| # | Problem | Difficulty | Solution | Topics |
|---|---|---|---|---|
| 15 | Best Time to Buy and Sell Stock | 🟢 Easy | C# | Sliding Window, Greedy |
| 16 | Longest Substring Without Repeating Characters | 🟡 Medium | C# | Sliding Window, Hash Set |
| 17 | Longest Repeating Character Replacement | 🟡 Medium | C# | Sliding Window, Hash Map |
| 18 | Permutation in String | 🟡 Medium | C# | Sliding Window, Hash Map |
| 19 | Minimum Window Substring | 🔴 Hard | C# | Sliding Window, Hash Map |
| 20 | Sliding Window Maximum | 🔴 Hard | C# | Sliding Window, Deque, Monotonic Queue |
Key Patterns:
- Variable/fixed window size
- Hash map for character frequency
- Expand and shrink technique
| # | Problem | Difficulty | Solution | Topics |
|---|---|---|---|---|
| 21 | Valid Parentheses | 🟢 Easy | C# | Stack, String |
| 22 | Min Stack | 🟡 Medium | C# | Stack, Design |
| 23 | Evaluate Reverse Polish Notation | 🟡 Medium | C# | Stack, Math |
| 24 | Generate Parentheses | 🟡 Medium | C# | Stack, Backtracking |
| 25 | Daily Temperatures | 🟡 Medium | C# | Stack, Monotonic Stack |
| 26 | Car Fleet | 🟡 Medium | C# | Stack, Sorting |
| 27 | Largest Rectangle in Histogram | 🔴 Hard | C# | Stack, Monotonic Stack |
| 28 | Online Stock Span | 🟡 Medium | C# | Stack, Monotonic Stack, Design |
Key Patterns:
- LIFO operations
- Monotonic stack for next greater/smaller element
- Backtracking with stack
| # | Problem | Difficulty | Solution | Topics |
|---|---|---|---|---|
| 29 | Binary Search | 🟢 Easy | C# | Binary Search |
| 30 | Search a 2D Matrix | 🟡 Medium | C# | Binary Search, Matrix |
| 31 | Koko Eating Bananas | 🟡 Medium | C# | Binary Search on Answer |
| 32 | Find Minimum in Rotated Sorted Array | 🟡 Medium | C# | Binary Search, Rotated Array |
| 33 | Search in Rotated Sorted Array | 🟡 Medium | C# | Binary Search, Rotated Array |
| 34 | Time Based Key-Value Store | 🟡 Medium | C# | Binary Search, Hash Map, Design |
| 35 | Median of Two Sorted Arrays | 🔴 Hard | C# | Binary Search, Divide and Conquer |
Key Patterns:
- Binary search on sorted arrays
- Binary search on answer space
- Rotated array modifications
- 2D matrix as 1D array
- Binary search for floor/ceiling values
| # | Problem | Difficulty | Solution | Topics |
|---|---|---|---|---|
| 36 | Reverse Linked List | 🟢 Easy | C# | Linked List, Recursion |
| 37 | Merge Two Sorted Lists | 🟢 Easy | C# | Linked List, Recursion |
| 38 | Linked List Cycle | 🟢 Easy | C# | Linked List, Two Pointers, Fast & Slow |
| 39 | Reorder List | 🟡 Medium | C# | Linked List, Two Pointers, Recursion |
| 40 | Remove Nth Node From End of List | 🟡 Medium | C# | Linked List, Two Pointers |
| 41 | Reverse Nodes in K-Group | 🔴 Hard | C# | Linked List, Recursion |
Key Patterns:
- Fast and slow pointer technique
- Dummy node for edge cases
- In-place reversal
- Two-pointer traversal
- Recursive solutions
| # | Problem | Difficulty | Solution | Topics |
|---|---|---|---|---|
| 42 | Insert Interval | 🟡 Medium | C# | Array, Binary Search, Merge |
| 43 | Merge Intervals | 🟡 Medium | C# | Array, Sorting, Greedy |
| 44 | Non-overlapping Intervals | 🟡 Medium | C# | Greedy, DP, Sorting |
| 45 | Meeting Rooms | 🟢 Easy | C# | Array, Sorting |
| 46 | Meeting Rooms II | 🟡 Medium | C# | Heap, Sorting, Sweep Line |
| 47 | Minimum Interval to Include Each Query | 🔴 Hard | C# | Heap, Sorting, Sweep Line |
Key Patterns:
- Sorting intervals by start or end time
- Merge overlapping intervals
- Sweep line algorithm with event processing
- Priority queue for interval scheduling
- Greedy approach for interval selection
- Language: C# (.NET 6.0+)
- IDE: Visual Studio / Visual Studio Code / Rider
- Version Control: Git & GitHub
- .NET SDK 6.0+
- Any C# IDE (Visual Studio, VS Code, Rider)
git clone https://github.com/yourusername/leetcode-150.git
cd leetcode-150Each solution is a self-contained C# class. You can:
- Copy individual solutions into your own project
- Create a console application and call the solution methods
- Use LeetCode's online judge to test the solutions
Example:
public class Program
{
public static void Main()
{
var solution = new Solution();
int[] nums = { 2, 7, 11, 15 };
int target = 9;
int[] result = solution.TwoSum(nums, target);
Console.WriteLine($"[{result[0]}, {result[1]}]");
}
}Each solution file includes:
/*
PROBLEM: Two Sum
Given an array of integers nums and an integer target, return indices
of the two numbers such that they add up to target.
...
*/// Calculate the complement needed to reach target
int complement = target - nums[i];/*
TIME COMPLEXITY: O(n)
- Single pass through array
- Hash map operations are O(1)
SPACE COMPLEXITY: O(n)
- Hash map stores up to n elements
*/- Key insights and intuition
- Step-by-step approach
- Edge cases handled
- NeetCode.io - Problem list and video explanations
- LeetCode - Practice platform
- Big-O Cheat Sheet - Algorithm complexity reference
While this is a personal learning repository, suggestions and improvements are welcome!
- Fork the repository
- Create a feature branch (
git checkout -b feature/improvement) - Commit your changes (
git commit -am 'Add improvement') - Push to the branch (
git push origin feature/improvement) - Open a Pull Request
- Solutions prioritize clarity and understanding over brevity
- Comments explain why, not just what
- Each solution includes alternative approaches when applicable
- Time/space complexity is always analyzed
This project is licensed under the MIT License - see the LICENSE file for details.
Karan Chadha
- GitHub: Karan Chadha Github
- LinkedIn: Karan Chadha LinkedIn
If you found this repository helpful, please give it a ⭐️!
Happy Coding! 💻✨
Last Updated: October 2025