Challenge - 5 Problems
Array Access Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateOutput of Array Update and Access
What is the output of the following C# code snippet?
DSA C#
int[] arr = {1, 2, 3, 4, 5}; arr[2] = arr[4] + arr[0]; Console.WriteLine(string.Join(", ", arr));
Attempts:
2 left
💡 Hint
Remember array indexing starts at 0 and addition is done before assignment.
✗ Incorrect
arr[2] is updated to arr[4] + arr[0] which is 5 + 1 = 6. The array becomes [1, 2, 6, 4, 5].
❓ Predict Output
intermediateArray Element After Multiple Updates
What is the value of arr[1] after running this code?
DSA C#
int[] arr = {10, 20, 30, 40}; arr[1] = arr[3] - arr[0]; arr[3] = arr[1] + 5;
Attempts:
2 left
💡 Hint
Update arr[1] first, then use its new value to update arr[3].
✗ Incorrect
arr[1] = arr[3] - arr[0] = 40 - 10 = 30. Then arr[3] = arr[1] + 5 = 30 + 5 = 35. So arr[1] is 30.
🔧 Debug
advancedIdentify the Error in Array Update
What error will this C# code produce when run?
DSA C#
int[] arr = new int[3]; arr[0] = 5; arr[3] = 10; Console.WriteLine(arr[0]);
Attempts:
2 left
💡 Hint
Check the valid index range for the array.
✗ Incorrect
The array has size 3, so valid indices are 0, 1, and 2. Accessing arr[3] causes IndexOutOfRangeException.
❓ Predict Output
advancedFinal Array State After Multiple Updates
What is the final state of the array after executing this code?
DSA C#
int[] arr = {2, 4, 6, 8}; arr[1] = arr[2] + arr[3]; arr[2] = arr[0] * 2; arr[3] = arr[1] - arr[2];
Attempts:
2 left
💡 Hint
Update step by step and track each change carefully.
✗ Incorrect
Step 1: arr[1] = 6 + 8 = 14
Step 2: arr[2] = 2 * 2 = 4
Step 3: arr[3] = 14 - 4 = 10
Final array: [2, 14, 4, 10]
❓ Predict Output
expertOutput After Complex Array Index Updates
What is printed by this C# code?
DSA C#
int[] arr = {1, 3, 5, 7, 9}; int i = 1; arr[i] = arr[i + 1] + arr[i - 1]; i = 3; arr[i] = arr[i] + arr[i - 2]; Console.WriteLine(string.Join(", ", arr));
Attempts:
2 left
💡 Hint
Update arr[1] first, then arr[3], carefully using updated values.
✗ Incorrect
First, i=1: arr[1] = arr[2] + arr[0] = 5 + 1 = 6. Array: [1, 6, 5, 7, 9]
Then i=3: arr[3] = arr[3] + arr[1] = 7 + 6 = 13. Array: [1, 6, 5, 13, 9]
Output: 1, 6, 5, 13, 9
