Welcome to my NeetCode 150 Solutions repository! 🎯 This repository contains my solutions to the popular NeetCode 150 problem list, covering essential topics for technical interviews such as arrays, strings, linked lists, trees, dynamic programming, and more.
The NeetCode 150 is a carefully curated list of 150 LeetCode problems designed to help you master data structures and algorithms for technical interviews. It’s structured by topic and difficulty, making it an excellent resource for systematic learning.
- Key Skills: HashMap, HashSet, frequency counter, sliding window
- Must Know:
- Time complexity of common operations
- When to use
Set
vsMap
- Sliding window pattern for subarrays
- Use Case: Solving problems with sorted arrays or finding pairs
- Essential Tips:
- One pointer starts from beginning, other from end
- Avoid extra space — great for in-place solutions
- Used in:
- Merging sorted arrays
- Removing duplicates
- Finding palindromes
- Use Case: Finding subarrays that satisfy a condition (sum, max, min)
- Key Ideas:
- Fixed size vs variable size window
- Avoid recomputation — update window as you slide
- Important for optimizing time to
O(n)
- Use Case: Search problems on sorted data
- Core Ideas:
- Always think of
low
,mid
,high
- Binary search can be applied on the answer (search space)
- Watch out for overflow:
mid = low + (high - low) // 2
- Always think of
- Use Case: Dynamic memory allocation, pointer manipulation
- Must Know:
- Use dummy node to simplify code
- Be cautious of null pointers
- Learn reversing a linked list (both iterative and recursive)
- Use Case: Optimal substructure problems like Fibonacci, knapsack
- Strategy:
- Identify overlapping subproblems
- Use recursion + memoization or bottom-up tabulation
- Think about state:
dp[i]
means what?
- Use Case: Calendar scheduling, merging ranges
- Tips:
- Always sort intervals by start time
- Merge by comparing
current.end
vsnext.start
- Greedy is often useful
- Use Case: Tree traversal, manipulation, recursion
- Core Patterns:
- Preorder, Inorder, Postorder (DFS)
- Level Order (BFS)
- Use stack for DFS, queue for BFS
- Use Case: Networks, pathfinding
- Key Concepts:
- BFS for shortest path (unweighted)
- DFS for connectivity
- Use adjacency list for efficiency
- Detect cycles, topological sort
- Use Case: Kth largest, sorting on-the-fly
- Things to Know:
- Min-heap and max-heap
PriorityQueue
in Java orheapq
in Python- Keep size small with
heapq.heappushpop
- Use Case: Permutations, combinations, constraint problems
- Tips:
- Try → Recurse → Undo
- Prune paths early for optimization
- Use visited/used arrays
- Use Case: Efficient toggling, checking states
- Important Techniques:
x ^ x = 0
(XOR)- Shift operators
<<
,>>
- Check bit:
(n & (1 << i))
- Use Case: Next greater element, valid parentheses
- Key Notes:
- Store indices for range-related problems
- Useful in histogram, stock span
- Be careful with decreasing vs increasing stack
- Use Case: Prefix searching, autocomplete
- Concepts:
- Tree-like structure of characters
- Each node is a character; edge is prefix
- Useful for
startsWith
,search
- Use Case: Making the best local choice for optimal global result
- Core Idea:
- Works when the problem has a "greedy-choice property"
- Examples: Jump Game, Activity Selection, Gas Station
- Fork this repo 🍴
- Solve problems one by one ✍️
- Track your progress 📈
- Learn patterns, not just solutions 💡
Feel free to open issues or pull requests for:
- Improvements
- Adding solutions in other languages
- Better explanations
- Inspired by NeetCode.io
- Built to improve problem-solving skills & prepare for coding interviews