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