Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @param {list_int32} maximum_jump_lengths
- * @return {bool}
- */
- function can_reach_last_house(maximum_jump_lengths) {
- // Write your code here.
- let reqLen=maximum_jump_lengths.length+1
- let canReachEndFrom=new Array(reqLen).fill(false)
- canReachEndFrom[reqLen-1]=true;
- let last_jump_house = reqLen-1;
- for(let startHouse=reqLen-2;startHouse>0;startHouse--){
- if(startHouse + maximum_jump_lengths[startHouse-1] >= last_jump_house) {
- canReachEndFrom[startHouse] = true;
- last_jump_house = startHouse;
- }
- }
- return canReachEndFrom[1];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement