Jump Game III

MediumGraphsbfs

Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.

Practice this as a mock interviewFree to start, no account needed

Problem

You are given an array arr of non-negative integers and a starting index start. When you stand at index i, you may jump to index i + arr[i] or to index i - arr[i], as long as the destination stays inside the array. Return true if, starting from start, you can reach **any** index whose value is 0. Otherwise return false.

Examples

Input: arr = [3,1,2,0,4,2], start = 5
Output: true
From index 5 (value 2) jump left to index 3, which holds `0`.
Input: arr = [2,1,3,1,2], start = 0
Output: false
The array has no `0`, so no jump sequence can succeed.

Constraints

  • 1 <= arr.length <= 5 * 10^4
  • 0 <= arr[i] < arr.length
  • 0 <= start < arr.length

What the interviewer grades

A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.

More bfs problems