PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates graph-traversal and modular arithmetic skills by requiring modeling a circular array as a state graph and determining reachability and minimum-distance jumps under wrap-around constraints.

  • medium
  • Uber
  • Coding & Algorithms
  • Software Engineer

Find shortest jumps in circular array

Company: Uber

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

You are given a circular array `arr` of length `n`. From index `i`, you may jump exactly `arr[i]` steps either to the left or to the right (wrapping around the array), i.e. you can move to: - `(i + arr[i]) mod n` - `(i - arr[i]) mod n` Given two indices `start` and `target` (0-based), return the minimum number of jumps needed to reach `target` starting from `start`. If it is impossible to reach `target`, return `-1`. Clarifications: - Each jump uses the value at your current index to determine the exact jump distance. - The array is circular, so indices wrap around using modulo `n`. Example: - `arr = [2, 1, 2, 3]`, `start = 0`, `target = 3` - From 0 you can go to 2 (right) or 2 (left) → 2 - From 2 you can go to 0 or 0 → cannot reach 3 → return `-1`. Implement a function to compute this minimum jump count.

Quick Answer: This question evaluates graph-traversal and modular arithmetic skills by requiring modeling a circular array as a state graph and determining reachability and minimum-distance jumps under wrap-around constraints.

You are given a circular array `arr` of length `n`. From index `i`, you must jump exactly `arr[i]` positions either to the left or to the right, wrapping around the array. From index `i`, the two possible next indices are: - `(i + arr[i]) mod n` - `(i - arr[i]) mod n` Given two 0-based indices `start` and `target`, return the minimum number of jumps needed to reach `target` starting from `start`. If it is impossible to reach `target`, return `-1`. Notes: - Each jump uses the value at your current index. - The array is circular, so indices always wrap using modulo `n`. - If `start` is already equal to `target`, the answer is `0`.

Constraints

  • 1 <= len(arr) <= 200000
  • 0 <= arr[i] <= 10^9
  • 0 <= start, target < len(arr)

Examples

Input: ([2, 1, 2, 3], 0, 3)

Expected Output: -1

Explanation: From index 0 you can only reach index 2, and from index 2 you can only return to index 0, so index 3 is unreachable.

Input: ([1, 1, 1, 1], 0, 2)

Expected Output: 2

Explanation: One shortest path is 0 -> 1 -> 2. Another is 0 -> 3 -> 2.

Input: ([0], 0, 0)

Expected Output: 0

Explanation: The start index is already the target, so no jumps are needed.

Input: ([0, 2, 1], 0, 2)

Expected Output: -1

Explanation: At index 0, the jump size is 0, so both left and right jumps stay at index 0 forever.

Input: ([5, 3, 1, 2], 0, 1)

Expected Output: 1

Explanation: With n = 4, jumping 5 positions is equivalent to jumping 1 position. From index 0, you can reach index 1 in one jump.

Input: ([2, 2, 2, 2, 2], 0, 1)

Expected Output: 2

Explanation: From index 0 you can go to 2 or 3. Then from 3 you can go to 1, so the minimum is 2 jumps.

Hints

  1. Treat each index as a node in a graph, with up to two outgoing edges to the indices you can jump to.
  2. Since every jump has the same cost, a level-by-level traversal helps find the minimum number of jumps.
Last updated: May 25, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Maximize Throughput and Count Trigger Components - Uber (medium)
  • Replace Dashes With Nearest Letters - Uber (medium)
  • Find Earliest Column With One - Uber (easy)
  • Solve Wonderful Strings and Grid Queries - Uber (hard)
  • Count Islands After Land Additions - Uber (medium)