0
0
Kotlinprogramming~20 mins

Take, drop, and chunked in Kotlin - Practice Problems & Coding Challenges

Choose your learning style9 modes available
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
intermediate
2: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)
A[10, 20, 30, 40]
B[10, 20]
C[30, 40, 50]
D[10, 20, 30]
Attempts:
2 left
💡 Hint
The take() function returns the first N elements from the list.
Predict Output
intermediate
2: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)
A[c, d, e]
B[a, b]
C[a, b, c]
D[d, e]
Attempts:
2 left
💡 Hint
drop() removes the first N elements and returns the rest.
Predict Output
advanced
2: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)
A[[1, 2], [3, 4], [5, 6], [7]]
B[[1, 2, 3], [4, 5, 6], [7]]
C[[1, 2, 3], [4, 5, 6], [7, 0, 0]]
D[[1, 2, 3, 4], [5, 6, 7]]
Attempts:
2 left
💡 Hint
chunked() splits the list into groups of the given size; the last chunk may be smaller.
🧠 Conceptual
advanced
2: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)?
Atake(3) returns [], drop(2) returns [], chunked(4) returns []
Btake(3) throws an exception, drop(2) returns [], chunked(4) returns [[]]
Ctake(3) returns [], drop(2) returns [], chunked(4) throws an exception
Dtake(3) returns [], drop(2) throws an exception, chunked(4) returns []
Attempts:
2 left
💡 Hint
These functions handle empty lists gracefully without errors.
Predict Output
expert
3: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)
A[[4, 5], [6, 7], [8, 9]]
B[[1, 2], [3, 4], [5, 6]]
C[[3, 4], [5, 6], [7]]
D[[3, 4], [5, 6], [7, 8]]
Attempts:
2 left
💡 Hint
Remember the order: drop first, then take, then chunked.