Challenge - 5 Problems
Master of Take, Drop, and Chunked
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this Kotlin code using take()?
Consider the following Kotlin code snippet. What will be printed?
Kotlin
val numbers = listOf(10, 20, 30, 40, 50) val result = numbers.take(3) println(result)
Attempts:
2 left
💡 Hint
The take() function returns the first N elements from the list.
✗ Incorrect
The take(3) function returns the first 3 elements from the list: 10, 20, and 30.
❓ Predict Output
intermediate2:00remaining
What does drop() return in this Kotlin example?
Look at this Kotlin code. What will be printed?
Kotlin
val letters = listOf('a', 'b', 'c', 'd', 'e') val result = letters.drop(2) println(result)
Attempts:
2 left
💡 Hint
drop() removes the first N elements and returns the rest.
✗ Incorrect
drop(2) removes the first two elements 'a' and 'b', returning the rest: 'c', 'd', 'e'.
❓ Predict Output
advanced2:00remaining
What is the output of chunked() with a list size not divisible by chunk size?
What will this Kotlin code print?
Kotlin
val nums = listOf(1, 2, 3, 4, 5, 6, 7) val chunks = nums.chunked(3) println(chunks)
Attempts:
2 left
💡 Hint
chunked() splits the list into groups of the given size; the last chunk may be smaller.
✗ Incorrect
chunked(3) splits the list into groups of 3 elements. The last group has only one element because the list size is 7.
🧠 Conceptual
advanced2:00remaining
How do take(), drop(), and chunked() behave on empty lists?
Given an empty list in Kotlin, what will be the result of calling take(3), drop(2), and chunked(4)?
Attempts:
2 left
💡 Hint
These functions handle empty lists gracefully without errors.
✗ Incorrect
All three functions return empty lists when called on an empty list; none throws exceptions.
❓ Predict Output
expert3:00remaining
What is the output of this combined take, drop, and chunked Kotlin code?
Analyze this Kotlin code and determine what it prints.
Kotlin
val data = (1..10).toList() val result = data.drop(2).take(5).chunked(2) println(result)
Attempts:
2 left
💡 Hint
Remember the order: drop first, then take, then chunked.
✗ Incorrect
drop(2) removes 1 and 2, leaving 3 to 10. take(5) selects 3 to 7. chunked(2) groups them as [3,4], [5,6], [7].