Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if we can jump from the first position.
DSA Python
def can_jump(nums): max_reach = 0 for i in range(len(nums)): if i > [1]: return False max_reach = max(max_reach, i + nums[i]) return True
Attempts:
3 left
💡 Hint
Common Mistakes
Using i instead of max_reach in the if condition.
Comparing with nums[i] instead of max_reach.
✗ Incorrect
We check if the current index i is beyond the maximum reachable index max_reach. If yes, we cannot proceed further.
2fill in blank
mediumComplete the code to update the maximum reachable index.
DSA Python
def can_jump(nums): max_reach = 0 for i in range(len(nums)): if i > max_reach: return False max_reach = [1](max_reach, i + nums[i]) return True
Attempts:
3 left
💡 Hint
Common Mistakes
Using min() instead of max() causes wrong max_reach updates.
Using sum() or abs() which are not suitable here.
✗ Incorrect
We use max() to update max_reach to the farthest index reachable so far.
3fill in blank
hardFix the error in the loop to iterate over all indices.
DSA Python
def can_jump(nums): max_reach = 0 for i in [1](len(nums)): if i > max_reach: return False max_reach = max(max_reach, i + nums[i]) return True
Attempts:
3 left
💡 Hint
Common Mistakes
Using enumerate() returns tuples, not just indices.
Using list(len(nums)) causes error.
✗ Incorrect
range(len(nums)) generates indices from 0 to len(nums)-1 for iteration.
4fill in blank
hardFill both blanks to create a function that returns True if last index is reachable.
DSA Python
def can_jump(nums): max_reach = 0 for i in [1](len(nums)): if i > max_reach: return [2] max_reach = max(max_reach, i + nums[i]) return True
Attempts:
3 left
💡 Hint
Common Mistakes
Returning True inside the loop incorrectly.
Using len() instead of range() for iteration.
✗ Incorrect
We iterate over indices with range and return False if we cannot reach current index.
5fill in blank
hardFill all three blanks to create a dictionary comprehension that maps each index to its max reachable position if reachable.
DSA Python
def jump_map(nums): max_reach = [3] return {i: i + nums[i] for i in [1](len(nums)) if i [2] max_reach}
Attempts:
3 left
💡 Hint
Common Mistakes
Using < instead of <= causes missing reachable index.
Initializing max_reach incorrectly.
✗ Incorrect
We use range(len(nums)) to iterate indices, check if i <= max_reach to ensure reachability, and initialize max_reach to 0.
