Bird
Raised Fist0

Which line contains a subtle bug that can cause incorrect jump counts on some inputs?

medium🐞 Bug Identification Q7 of Q15
Greedy Algorithms - Jump Game II (Minimum Jumps)
Examine the following greedy code snippet for Jump Game II. Which line contains a subtle bug that can cause incorrect jump counts on some inputs? ```python def jump(nums): jumps = 0 current_end = 0 furthest = 0 for i in range(len(nums)): furthest = max(furthest, i + nums[i]) if i == current_end: jumps += 1 # Missing update of current_end here return jumps ```
ALine updating furthest = max(furthest, i + nums[i])
BLine checking if i == current_end
CLine incrementing jumps += 1
DMissing line updating current_end after incrementing jumps
Step-by-Step Solution
Solution:
  1. Step 1: Identify missing update

    The code increments jumps but does not update current_end, causing infinite or incorrect jumps.
  2. Step 2: Pinpoint bug location

    The missing update after jumps increment is the root cause, not the furthest update line.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Without current_end update, jump boundaries never advance [OK]
Quick Trick: Always update current_end after jumps increment [OK]
Common Mistakes:
MISTAKES
  • Forgetting to update current_end
  • Misplacing jump increment
Trap Explanation:
PITFALL
  • Candidates often blame furthest update line, but bug is missing current_end update.
Interviewer Note:
CONTEXT
  • Tests bug spotting in greedy jump implementation.
Master "Jump Game II (Minimum Jumps)" in Greedy Algorithms

3 interactive learning modes - each teaches the same concept differently

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Greedy Algorithms Quizzes