Challenge - 5 Problems
Array Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateOutput of Array Initialization with Default Values
What is the output of the following Go code snippet that declares and initializes an array?
DSA Go
package main import "fmt" func main() { var arr [5]int fmt.Println(arr) }
Attempts:
2 left
💡 Hint
Arrays in Go are initialized with zero values for their type.
✗ Incorrect
In Go, when you declare an array without explicit initialization, all elements are set to the zero value of the element type. For int, zero value is 0.
❓ Predict Output
intermediateOutput of Array Initialization with Partial Values
What is the output of this Go code that partially initializes an array?
DSA Go
package main import "fmt" func main() { arr := [5]int{1, 2} fmt.Println(arr) }
Attempts:
2 left
💡 Hint
Uninitialized elements in an array get the zero value of the type.
✗ Incorrect
The array is declared with 5 elements, but only first two are initialized. The rest default to 0.
❓ Predict Output
advancedOutput of Array Initialization Using Index Keys
What will be printed by this Go program that initializes an array using index keys?
DSA Go
package main import "fmt" func main() { arr := [5]int{2: 10, 4: 20} fmt.Println(arr) }
Attempts:
2 left
💡 Hint
Index keys specify which positions get assigned values.
✗ Incorrect
Only positions 2 and 4 are assigned values 10 and 20 respectively. Others remain zero.
🔧 Debug
advancedIdentify the Error in Array Declaration
What error will this Go code produce when compiled?
DSA Go
package main
func main() {
var arr [3]int = [4]int{1, 2, 3, 4}
}Attempts:
2 left
💡 Hint
Array sizes must match exactly in Go assignments.
✗ Incorrect
The declared array size is 3, but the literal has size 4. This causes a type mismatch error.
🧠 Conceptual
expertArray Size Inference in Go
Which of the following array declarations in Go correctly infers the array size from the number of elements provided?
Attempts:
2 left
💡 Hint
The ... syntax lets Go count elements automatically.
✗ Incorrect
Using [...] tells Go to infer the array size from the number of elements in the literal. Option C uses this correctly.
