Company: Nxtwave_13dec
Difficulty: medium
Minimum Jumps Using Teleportation Description You are given an integer array arr of size n . From an index i , you can move to: 1) index i - 1 , if i - 1 >= 0 . 2) index i + 1 , if i + 1 . 3) index j , if arr[i] is a prime number and arr[j] % arr[i] == 0 . Define the cost of index i as the minimum number of steps needed to reach index i from index 0 . You need to find the cost for each index i (where 0 <= i < n). Example 1 Input: n = 4 arr = [1, 2, 4, 6] Output: 0 1 2 2 Explanation: For index 0, it takes 0 steps. For index 1, path: 0 → 1. (1 step) For index 2, path: 0 → 1 → 2. (2 steps) For index 3, path: 0 → 1 → 3. (2 steps). From index 1, arr[1]=2 is prime, and we can teleport to index 3 since arr[3]=6 is divisible by 2. Example 2 Input: n = 5 arr = [2, 3, 4, 7, 9] Output: 0 1 1 2 2 Explanation: For index 0, it takes 0 steps. For index 1, path: 0 → 1. (1 step) For index 2, path: 0 → 2. (1 step). From index 0, arr[0]=2 is prime, and we can tele