My first instinct was brute force, just simulate from every index and track visited states to catch cycles.
Model the jumps as a functional graph where each index points to its next index. Use memoization to determine for each index whether it eventually exits left, exits right, or loops, then find the smallest index that exits right or loops without ever exiting left. Alternatively, process indices from left to right, using a visited state array to avoid redundant work and achieve O(n) time.
Pro tip: Clarify that 'never go out of bounds on the left' means the path may exit right or loop, but must not hit index < 0. This distinction is crucial and shows you pay attention to edge cases.
Confirm that 'never go out of bounds on the left' means the path may exit right or loop, but must not hit index < 0. Discuss edge cases like empty array, all jumps left, or immediate exit.
Treat each index as a node with a directed edge to i + arr[i]. The problem reduces to finding the smallest node whose path never reaches a node < 0.
Use a state array (e.g., 0=unvisited, 1=visiting, 2=safe, 3=left-exit) and DFS with cycle detection to classify each index. Alternatively, process indices from left to right, propagating states to achieve linear time.
Write code that iterates through indices, skipping already classified ones, and returns the smallest index that is safe (exits right or loops without left exit). Test with examples and edge cases.
Explain that each index is visited at most once, giving O(n) time and O(n) space for the state array. Discuss potential optimizations or trade-offs.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.