Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Jump game on GFG,forward motion only
- class Solution {
- public:
- int canReach(int arr[], int n) {
- int max_reach=arr[0],remaining=arr[0]-1;
- for(int i=1;i<n;i++){
- if(i>max_reach) return 0;
- max_reach=max(max_reach,arr[i]+i);
- remaining--;
- }
- return true;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment