Limited time: AI code review, hints, mock interviews, whiteboard analysis, and all Pro features are unlocked. Enroll

Jump Game IV

Hard

Topics
ArrayBFSHash Table

Given an integer array nums, you start at index 0. From index i you can move to i+1, i-1, or any index j with nums[j] == nums[i] (all within bounds). Return the minimum number of steps to reach the last index.

Example 1

Input:  nums = [100,-23,-23,404,100,23,23,23,3,404]
Output: 3

Example 2

Input:  nums = [7]
Output: 0

Example 3

Input:  nums = [7,6,9,6,9,6,9,7]
Output: 1

Constraints

  • 1 <= nums.length <= 5*10^4
  • -10^8 <= nums[i] <= 10^8
Run ⌘' · Submit ⌘⏎
SensAI SensAI
Beta
Listening...
Tap mic to stop voice mode

Unlock AI Features

One click to activate - no payment, no credit card. Just sign in and you're in.

AI code review and hints
SensAI chat assistant
AI mock interviews
Whiteboard analysis
100% free during early access