class Solution {
public:
int jump(int A[], int n) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
if (n == 1) return 0;
int pos = 0;
int far = 0;
for (int step = 1; pos <= far; step++) {
for (int stop = far; pos <= stop; pos++) {
far = max(far, pos + A[pos]);
if (far >= n - 1) return step;
}
}
return 0;
}
};
Small Case: 4ms
Large Case: 44ms
Time: O(n)
Space: O(1)