DSA - 1 New, 1 Revision (DP, Greedy, Heaps)
New Problem
55. Jump Game
DP (Bottom-up):
- Create
dp[], setdp[last] = true - Fill from right to left using reachable indices i.e.
dp[i+jumps] - Optimization:
- Without pruning overflow jumps β exponential
- Even optimized DP β O(nΒ²)
- Create
Greedy - O(n):
- Maintain
goal = last index - Traverse backwards
- If
i + nums[i] >= goalβ updategoal = i - Final check β
goal == 0
- Maintain
Comment:
Initially leaned towards backtracking (decision at each index), but constraints (nums[i] up to 10^5) made it infeasible. Key learning β recognize when brute force explodes due to branching factor. DP gave structure, but greedy revealed the optimal path.
Revision
295. Find Median from Data Stream
- Optimal: two heaps
maxHeap (left)β smaller halfminHeap (right)β larger half- Insert β rebalance β compute median
- Median Logic:
- Equal size β average of tops
- Unequal β top of minHeap
Comment:
- First exposure β implemented a naive solution which exceeded time limit; Studied optimal solution using heaps/PQs.
- Second attempt β implemented smoothly (<15 mins)
- Reinforced understanding of heap-based streaming problems
Learning
Started watching Aditya Vermaβs DP playlist on YouTube to build intuition.
Early impression β structured and promising.
Reflection
Solving more Blind 75 problems is leading to clear improvements in both coding ability and problem-solving. Confidence is becoming practical rather than theoretical. Key shift: From βwhat approach to use?β β βwhich approach is optimal here and why?β
Growth is tangible.