Challenge - 5 Problems
Array Access and Update Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateOutput of Array Update at Specific Index
What is the output of the following Go code after updating the array element at index 2?
DSA Go
package main import "fmt" func main() { arr := [5]int{10, 20, 30, 40, 50} arr[2] = 99 fmt.Println(arr) }
Attempts:
2 left
💡 Hint
Remember that array indices start at 0 in Go.
✗ Incorrect
The code updates the element at index 2 (third element) to 99. The rest remain unchanged.
❓ Predict Output
intermediateAccessing Array Element by Index
What will be printed by this Go program?
DSA Go
package main import "fmt" func main() { arr := [4]string{"a", "b", "c", "d"} fmt.Println(arr[3]) }
Attempts:
2 left
💡 Hint
Array indices start at 0.
✗ Incorrect
Index 3 is the fourth element, which is "d".
❓ Predict Output
advancedEffect of Multiple Updates on Array
What is the final state of the array after all updates?
DSA Go
package main import "fmt" func main() { arr := [3]int{1, 2, 3} arr[0] = arr[1] + arr[2] arr[2] = arr[0] - arr[1] arr[1] = arr[2] * 2 fmt.Println(arr) }
Attempts:
2 left
💡 Hint
Update step by step and keep track of changes carefully.
✗ Incorrect
Step 1: arr[0] = 2 + 3 = 5
Step 2: arr[2] = 5 - 2 = 3
Step 3: arr[1] = 3 * 2 = 6
But note arr[1] was 2 at step 2, so step 2 uses old arr[1]. Final array is [5 6 3]. Check carefully.
❓ Predict Output
advancedWhat error occurs when accessing invalid index?
What error will this Go program produce?
DSA Go
package main
func main() {
arr := [2]int{1, 2}
_ = arr[3]
}Attempts:
2 left
💡 Hint
Accessing an index outside array bounds causes runtime panic.
✗ Incorrect
Index 3 is out of range for array of length 2, causing runtime panic.
🧠 Conceptual
expertArray Update and Memory Behavior in Go
Consider this Go code snippet. What is the output and why?
DSA Go
package main import "fmt" func main() { arr := [3]int{1, 2, 3} slice := arr[:] slice[1] = 99 fmt.Println(arr) }
Attempts:
2 left
💡 Hint
Slices share the underlying array memory.
✗ Incorrect
The slice references the original array memory. Changing slice[1] changes arr[1].
