0
0
DSA Pythonprogramming~20 mins

Array Access and Update at Index in DSA Python - Practice Problems & Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Array Access and Update Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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)
A[5, 10, 15, 20, 25]
B[5, 100, 15, 20, 25]
C[100, 10, 15, 20, 25]
D[5, 10, 100, 20, 25]
Attempts:
2 left
💡 Hint
Remember that list indices start at 0 in Python.
Predict Output
intermediate
2: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)
A[10, 2, 3, 4, 50]
B[1, 2, 3, 4, 5]
C[10, 2, 3, 4, 5]
D[1, 2, 3, 4, 50]
Attempts:
2 left
💡 Hint
Check which indices are updated and what values they get.
🔧 Debug
advanced
2: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)
ANo error, output: [7, 8, 9, 10]
BTypeError: 'int' object is not subscriptable
CIndexError: list assignment index out of range
DSyntaxError: invalid syntax
Attempts:
2 left
💡 Hint
Check the valid indices for the array of length 3.
🧠 Conceptual
advanced
2: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)
A[100, 6, 9, 12]
B[3, 6, 9, 100]
C[3, 6, 100, 12]
DIndexError: list assignment index out of range
Attempts:
2 left
💡 Hint
Negative indices count from the end of the list in Python.
🚀 Application
expert
3: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)
A[6, 1, 4, 6, 8, 5]
B[5, 1, 4, 6, 8, 5]
C[6, 1, 2, 3, 4, 5]
D[0, 1, 4, 6, 8, 5]
Attempts:
2 left
💡 Hint
Trace each update step carefully, especially the loop and the final assignment.