Untitled

 avatar
unknown
plain_text
5 months ago
586 B
6
Indexable
class Solution {
    public int jump(int[] arr) {
        int jumps = 0;
        int i = 0, j = 0; // i and j represent the current level bounds
        int n = arr.length;

        while (j < n - 1) {
            int maxRange = 0;

            // Explore all indices in the current level
            for (int index = i; index <= j; index++) {
                maxRange = Math.max(maxRange, index + arr[index]);
            }

            i = j + 1;  // Move to the next level
            j = maxRange;
            jumps++;
        }

        return jumps;
    }
}
Editor is loading...
Leave a Comment