Challenge - 5 Problems
Array Access and Update Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output after updating array element at index
What is the output of the following Python code after updating the element at index 2?
DSA Python
arr = [5, 10, 15, 20, 25] arr[2] = 100 print(arr)
Attempts:
2 left
💡 Hint
Remember that list indices start at 0 in Python.
✗ Incorrect
The element at index 2 (third element) is updated from 15 to 100. The rest remain unchanged.
❓ Predict Output
intermediate2:00remaining
Output after multiple updates on array
What will be printed after these updates to the array?
DSA Python
arr = [1, 2, 3, 4, 5] arr[0] = 10 arr[4] = 50 print(arr)
Attempts:
2 left
💡 Hint
Check which indices are updated and what values they get.
✗ Incorrect
The first element (index 0) is changed to 10 and the last element (index 4) to 50.
🔧 Debug
advanced2:00remaining
Identify the error when updating an array index
What error will this code produce when run?
DSA Python
arr = [7, 8, 9] arr[3] = 10 print(arr)
Attempts:
2 left
💡 Hint
Check the valid indices for the array of length 3.
✗ Incorrect
Index 3 does not exist in the array of length 3 (indices 0,1,2). Trying to assign to it causes IndexError.
🧠 Conceptual
advanced2:00remaining
Effect of negative index update on array
What is the output after updating the array element at index -1?
DSA Python
arr = [3, 6, 9, 12] arr[-1] = 100 print(arr)
Attempts:
2 left
💡 Hint
Negative indices count from the end of the list in Python.
✗ Incorrect
Index -1 refers to the last element, so it updates 12 to 100.
🚀 Application
expert3:00remaining
Final array after sequence of updates and accesses
Given the code below, what is the final printed array?
DSA Python
arr = [0, 1, 2, 3, 4, 5] for i in range(2, 5): arr[i] = arr[i] * 2 arr[0] = arr[5] + arr[1] print(arr)
Attempts:
2 left
💡 Hint
Trace each update step carefully, especially the loop and the final assignment.
✗ Incorrect
Elements at indices 2,3,4 are doubled: 2->4, 3->6, 4->8. Then arr[0] = arr[5] + arr[1] = 5 + 1 = 6.