Challenge - 5 Problems
Array Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of array initialization and access
What is the output of this Go program that initializes an array and prints its elements?
Go
package main import "fmt" func main() { var arr [3]int = [3]int{10, 20, 30} for i := 0; i < len(arr); i++ { fmt.Print(arr[i], " ") } }
Attempts:
2 left
💡 Hint
Remember arrays hold fixed-size collections of elements of the same type.
✗ Incorrect
The array is initialized with values 10, 20, 30. The loop prints each element separated by space, so output is '10 20 30 '.
🧠 Conceptual
intermediate1:30remaining
Why use arrays instead of separate variables?
Why are arrays useful compared to using many separate variables for similar data?
Attempts:
2 left
💡 Hint
Think about how you handle many similar items in real life, like a row of mailboxes.
✗ Incorrect
Arrays let you keep many values together under one name, making it easier to store, access, and manage related data.
❓ Predict Output
advanced2:00remaining
Output when modifying array elements
What is the output of this Go program that modifies an array element?
Go
package main import "fmt" func main() { arr := [4]int{1, 2, 3, 4} arr[2] = 10 fmt.Println(arr) }
Attempts:
2 left
💡 Hint
Arrays allow changing values at specific positions by index.
✗ Incorrect
The element at index 2 (third element) is changed from 3 to 10, so the array prints as [1 2 10 4].
🔧 Debug
advanced2:00remaining
Identify the error in array declaration
What error does this Go code produce and why?
Go
package main func main() { var arr [3]int = [4]int{1, 2, 3, 4} }
Attempts:
2 left
💡 Hint
Check if the array sizes on both sides match.
✗ Incorrect
The variable arr is declared as an array of size 3 but assigned an array literal of size 4, causing a type mismatch error.
🚀 Application
expert2:30remaining
Count how many elements in an array are greater than 5
What is the value of count after running this Go code?
Go
package main import "fmt" func main() { arr := [5]int{3, 7, 2, 9, 5} count := 0 for _, v := range arr { if v > 5 { count++ } } fmt.Println(count) }
Attempts:
2 left
💡 Hint
Look at each element and count only those greater than 5.
✗ Incorrect
Only 7 and 9 are greater than 5, so count is 2.