[InterviewBit] Jump Game Array

Jump Game Array

  • Time :
  • Space :
1
2
3
4
5
6
7
8
9
10
int Solution::canJump(vector<int> &A) {
int p = 0, ma = 0, n = A.size();
while(p <= ma and p < n) {
ma = max(ma, A[p] + p);
if(ma > p) p++;
else break;
}
return p >= n - 1;
}

Author: Song Hayoung
Link: https://songhayoung.github.io/2022/09/13/PS/interviewbit/jump-game-array/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.