Back to problems

Find smallest start index avoiding left exit

Algorithm · Uber · Hard

Let jump be a 0-indexed integer array with n elements. At any position i, the next position is $$i + jump[i]$$: a positive value in jump[i] moves right, a negative value moves left, and 0 leaves the position unchanged. Choose a starting index s satisfying $$0 \le s 2 -> 1, which never crosses the left border. Example 3: Explanation: The only start, 0, jumps to -1. Since the walk leaves through the left border, there is no valid starting index. Constraints: $$0 \le n \le…

Checking your access…