Complete the code to initialize the left pointer at the start of the array.
arr = [1, 3, 5, 7, 9] left = [1] right = len(arr) - 1 print(left, right)
The left pointer should start at index 0, which is the first element of the array.
Complete the code to move the right pointer one step to the left.
right = 5 right = right [1] 1 print(right)
To move the right pointer one step left, subtract 1 from it.
Fix the error in the loop condition to stop when left pointer crosses right pointer.
left = 0 right = 4 while left [1] right: print(left, right) left += 1 right -= 1
The loop should run while left is less than right to avoid crossing pointers.
Fill both blanks to create a two-pointer loop that swaps elements until pointers meet.
arr = [2, 4, 6, 8, 10] left = 0 right = len(arr) - 1 while left [1] right: arr[left], arr[right] = arr[right], arr[left] left = left [2] 1 right -= 1 print(arr)
The loop runs while left is less than right. Left pointer moves right by adding 1.
Fill all three blanks to create a dictionary comprehension that maps each element to its index if the element is even.
arr = [1, 2, 3, 4, 5] even_index_map = [1]: [2] for [3] in range(len(arr)) if arr[i] % 2 == 0 print(even_index_map)
The comprehension maps each even element (arr[i]) to its index (i). The loop variable is i.