Vijay Pagare

DSA - 3 new - DP, Hashmap


213. House Robber II

Insight: Same as House Robber (iterative DP). Since first & last are adjacent, split into 2 cases:

Comment: Brain fog. Couldn’t even recall/formulate base House Robber logic.


217. Contains Duplicate

Insight:

  1. Convert to Set → if size reduces → duplicate exists
  2. Use HashMap → check while inserting

Comment: Straightforward. Can do in O(n) using set/hash.


91. Decode Ways

Insight: DFS + memoization
Recurrence: dfs(i) = dfs(i+1) + dfs(i+2)
Base cases:

Comment: Weak formulation. Took help (NeetCode + Gemini) to complete.

#Dsa #Leetcode