You are given an integer array `nums` and two integers `start` and `end`, representing 0-indexed positions in `nums`. You can move from index `i` to index `j` (`i != j`) if and only if `nums[i]` is a multiple of `nums[j]`, or `nums[j]` is a multiple of `nums[i]`. Return the minimum number of moves to travel from index `start` to index `end`. If there is no possible path, return `-1`.
Explanation: Indices 0 (5) and 1 (15) are connected (15 is multiple of 5). Indices 1 (15) and 2 (3) are connected (15 is multiple of 3). Path: 0 -> 1 -> 2. Total edges: 2.
Analyze constraints and compute optimal solutions step-by-step.
No dry run loaded.
🚀 Practice this problem
Run code, get AI hints & track streak