#3629

Minimum Jumps to Reach End via Prime Teleportation

expert · 1110 · lc medium +32 · 31.8% accepted · 130 likes · top 9%

Description

An integer array nums of length n is given. Starting at index 0, reach index n - 1.

From any index i, you may:

- Adjacent Step: move to i + 1 or i - 1 (if in bounds).

- Prime Teleportation: if nums[i] is prime p, jump to any index j != i where nums[j] % p == 0.

Return the minimum number of jumps required.

Code

1
2
3