Complete the code to check if the array is empty and return true.
function canJump(nums: number[]): boolean {
if (nums.length [1] 0) return true;
// rest of the code
}We use strict equality === to check if the length is exactly zero.
Complete the code to initialize the farthest reachable index.
function canJump(nums: number[]): boolean {
let farthest = [1];
// rest of the code
}We start from index 0, so the farthest reachable index initially is 0.
Fix the error in the loop condition to iterate through the array correctly.
for (let i = 0; i [1] nums.length; i++) { // loop body }
The loop should run while i is less than nums.length to avoid going out of bounds.
Fill both blanks to update the farthest reachable index and check if current index is reachable.
if (i [1] farthest) { farthest = Math.max(farthest, i [2] nums[i]); }
We check if i is less than or equal to farthest to ensure the position is reachable. Then update farthest by adding nums[i] to i.
Fill all three blanks to return true if the last index is reachable, otherwise false.
return farthest [1]= nums.length [2] 1; // or return farthest [3] nums.length - 1;
We return true if farthest is greater than or equal to the last index (nums.length - 1). The second return uses less than to return false if not reachable.