Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to start binary search with the correct left pointer.
DSA Python
def find_min(nums): left = [1] right = len(nums) - 1 while left < right: mid = (left + right) // 2 if nums[mid] > nums[right]: left = mid + 1 else: right = mid return nums[left]
Attempts:
3 left
💡 Hint
Common Mistakes
Starting left pointer at 1 or negative index causes missing elements.
Starting left pointer at length of array causes index error.
✗ Incorrect
The left pointer should start at index 0 to cover the entire array.
2fill in blank
mediumComplete the code to correctly update the left pointer when mid element is greater than right element.
DSA Python
def find_min(nums): left = 0 right = len(nums) - 1 while left < right: mid = (left + right) // 2 if nums[mid] > nums[right]: left = [1] else: right = mid return nums[left]
Attempts:
3 left
💡 Hint
Common Mistakes
Setting left to mid causes infinite loop when left == mid.
Setting left to right or left + 1 without condition causes wrong results.
✗ Incorrect
If nums[mid] > nums[right], the minimum must be to the right of mid, so left moves to mid + 1.
3fill in blank
hardFix the error in updating the right pointer when mid element is less than or equal to right element.
DSA Python
def find_min(nums): left = 0 right = len(nums) - 1 while left < right: mid = (left + right) // 2 if nums[mid] > nums[right]: left = mid + 1 else: right = [1] return nums[left]
Attempts:
3 left
💡 Hint
Common Mistakes
Setting right to mid + 1 skips mid and may miss minimum.
Setting right to right - 1 can cause infinite loop or miss minimum.
✗ Incorrect
When nums[mid] <= nums[right], the minimum can be at mid, so right moves to mid.
4fill in blank
hardFill both blanks to create a dictionary comprehension that maps each number to its square only if the number is less than 5.
DSA Python
nums = [1, 3, 5, 7, 9] squares = [1]: [2] for num in nums if num < 5
Attempts:
3 left
💡 Hint
Common Mistakes
Using multiplication by 2 instead of square.
Using addition instead of square for values.
✗ Incorrect
The dictionary comprehension uses num as key and num squared as value for nums less than 5.
5fill in blank
hardFill all three blanks to create a dictionary comprehension that maps uppercase letters to their ASCII values only if the ASCII value is greater than 65.
DSA Python
letters = ['a', 'B', 'C', 'd', 'E'] ascii_map = [1]: [2] for letter in letters if ord(letter) [3] 65
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' in the condition.
Using letter instead of letter.upper() as key.
✗ Incorrect
The comprehension maps uppercase letters to their ASCII values where ASCII is greater than 65.
