Jump Game
Jump Game
Section titled “Jump Game”
Medium
Day 5 • Striver Blind 75
📌 Problem Overview
Section titled “📌 Problem Overview”Return true if you can reach the last index starting from index 0 with maximum jump lengths given by nums[i].
Examples & Constraints
Section titled “Examples & Constraints”Example 1:
- Input:
nums = [2,3,1,1,4] - Output:
true
Constraints:
1 <= nums.length <= 10^4
💡 Approach & Intuition
Section titled “💡 Approach & Intuition”Greedy backward goal post shift.
🎯 Pattern Recognition
Section titled “🎯 Pattern Recognition”Greedy Reachability
📊 Step-by-Step Execution (Mermaid Diagram)
Section titled “📊 Step-by-Step Execution (Mermaid Diagram)”graph TD Problem["Problem of Size N"] --> Sub["Break into Subproblems DP[i]"] Sub --> Base["Base Cases: DP[0], DP[1]"] Base --> Trans["State Transition: DP[i] = f(DP[i-1], DP[i-2], ...)"] Trans --> Table["Fill DP Table / Variables"] Table --> Result["Return DP[N]"]🐢 Brute Force Solution
Section titled “🐢 Brute Force Solution”function canJump(nums) { let goal = nums.length - 1; for (let i = nums.length - 1; i >= 0; i--) { if (i + nums[i] >= goal) goal = i; } return goal === 0;}- Time Complexity:
O(n) - Space Complexity:
O(1) - Explanation: Backward greedy goal post update.
⚡ Optimized Solution
Section titled “⚡ Optimized Solution”function canJump(nums) { let goal = nums.length - 1; for (let i = nums.length - 1; i >= 0; i--) { if (i + nums[i] >= goal) goal = i; } return goal === 0;}- Time Complexity:
O(n) - Space Complexity:
O(1) - Explanation: Greedy single pass.
🐾 Step-by-Step Walkthrough
Section titled “🐾 Step-by-Step Walkthrough”- Initialize State: Setup necessary pointers, dynamic programming arrays, or hash maps.
- Iterate & Evaluate: Process the input according to the boundary conditions.
- Update & Return: Compute the optimal answer and return early or at termination.
🎙️ FAANG Interview Pitch
Section titled “🎙️ FAANG Interview Pitch”Iterate backwards starting from end; if current index plus jump distance reaches goal, shift goal to current index.
💡 Progressive Hints
Section titled “💡 Progressive Hints”- Track target goal from right to left.