Challenge - 5 Problems
Zip Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of zipping two lists of different lengths?
Consider the following Kotlin code that uses
zip to combine two lists of different lengths. What will be printed?Kotlin
val list1 = listOf("a", "b", "c", "d") val list2 = listOf(1, 2) val zipped = list1.zip(list2) println(zipped)
Attempts:
2 left
💡 Hint
Remember that zip pairs elements until the shortest list ends.
✗ Incorrect
The zip function pairs elements from both lists until one list runs out of elements. Since list2 has only 2 elements, the result contains only 2 pairs.
❓ Predict Output
intermediate2:00remaining
What is the output when zipping with a transform function?
What will this Kotlin code print when using
zip with a transform lambda?Kotlin
val nums = listOf(1, 2, 3) val words = listOf("one", "two", "three") val result = nums.zip(words) { n, w -> "$w:$n" } println(result)
Attempts:
2 left
💡 Hint
The lambda receives elements from the first and second list in order.
✗ Incorrect
The lambda combines each pair as "word:number". So the output is a list of strings like "one:1".
🔧 Debug
advanced2:00remaining
Why does this zip code cause a compilation error?
This Kotlin code tries to zip two lists but causes a compilation error. What is the error?
Kotlin
val a = listOf(1, 2, 3) val b = listOf("x", "y") val zipped = a.zip(b) { x -> x.toString() } println(zipped)
Attempts:
2 left
💡 Hint
Check the lambda parameters for zip with transform.
✗ Incorrect
The zip function with a transform lambda expects two parameters: one from each list. Here, the lambda has only one parameter, causing a compilation error.
❓ Predict Output
advanced2:00remaining
What is the output of zipping a list with itself?
What will this Kotlin code print?
Kotlin
val list = listOf(10, 20, 30) val zipped = list.zip(list) println(zipped)
Attempts:
2 left
💡 Hint
Zipping a list with itself pairs elements at the same index.
✗ Incorrect
Zipping pairs elements by index. Since both lists are the same, pairs are identical elements.
🧠 Conceptual
expert2:00remaining
How many pairs are in the zipped list?
Given these Kotlin lists, how many pairs will the zipped list contain?
val first = listOf(1, 2, 3, 4, 5)
val second = listOf("a", "b", "c")Attempts:
2 left
💡 Hint
The zipped list length equals the shorter list length.
✗ Incorrect
The zip function stops pairing when the shortest list ends, so the result has 3 pairs.