Advertisement
rishu110067

Untitled

Jan 27th, 2022
1,227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * @param {list_int32} maximum_jump_lengths
  3.  * @return {bool}
  4.  */
  5. function can_reach_last_house(maximum_jump_lengths) {
  6.     // Write your code here.
  7.     let reqLen=maximum_jump_lengths.length+1
  8.     let canReachEndFrom=new Array(reqLen).fill(false)
  9.     canReachEndFrom[reqLen-1]=true;
  10.    
  11.     let last_jump_house = reqLen-1;
  12.     for(let startHouse=reqLen-2;startHouse>0;startHouse--){
  13.         if(startHouse + maximum_jump_lengths[startHouse-1] >= last_jump_house) {
  14.             canReachEndFrom[startHouse] = true;
  15.             last_jump_house = startHouse;
  16.         }
  17.     }
  18.    
  19.     return canReachEndFrom[1];
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement