Bird
Raised Fist0
Kotlinprogramming~20 mins

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

Choose your learning style10 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.

Practice

(1/5)
1. What does the Kotlin function take(3) do when called on a list?
easy
A. Returns the first 3 items of the list
B. Removes the first 3 items from the list
C. Splits the list into chunks of size 3
D. Returns the last 3 items of the list

Solution

  1. Step 1: Understand the take function

    The take(n) function returns the first n elements from a list.
  2. Step 2: Apply to the example

    Calling take(3) returns the first 3 items, not removing or splitting the list.
  3. Final Answer:

    Returns the first 3 items of the list -> Option A
  4. Quick Check:

    take(3) = first 3 items [OK]
Hint: Remember: take(n) grabs first n items [OK]
Common Mistakes:
  • Confusing take with drop
  • Thinking take removes items
  • Mixing take with chunked
2. Which of the following is the correct syntax to split a list myList into chunks of size 4 in Kotlin?
easy
A. myList.take(4)
B. chunked(myList, 4)
C. myList.drop(4)
D. myList.chunked(4)

Solution

  1. Step 1: Identify the chunked function usage

    The chunked(size) function is called as a method on the list with the chunk size as argument.
  2. Step 2: Check each option

    Only myList.chunked(4) matches the correct syntax. Others are either wrong method or wrong call style.
  3. Final Answer:

    myList.chunked(4) -> Option D
  4. Quick Check:

    chunked called as method with size [OK]
Hint: chunked is a method: list.chunked(size) [OK]
Common Mistakes:
  • Using chunked as a standalone function
  • Confusing chunked with take or drop
  • Wrong argument order
3. What is the output of the following Kotlin code?
val numbers = listOf(10, 20, 30, 40, 50, 60)
val result = numbers.drop(2).take(3)
println(result)
medium
A. [40, 50, 60]
B. [10, 20, 30]
C. [30, 40, 50]
D. [20, 30, 40]

Solution

  1. Step 1: Apply drop(2) on the list

    Dropping first 2 items removes 10 and 20, leaving [30, 40, 50, 60].
  2. Step 2: Apply take(3) on the dropped list

    Taking first 3 items from [30, 40, 50, 60] gives [30, 40, 50].
  3. Final Answer:

    [30, 40, 50] -> Option C
  4. Quick Check:

    drop(2) then take(3) = [30, 40, 50] [OK]
Hint: drop removes first n, then take picks next n [OK]
Common Mistakes:
  • Taking before dropping
  • Off-by-one errors in indexing
  • Confusing drop and take order
4. Identify the error in this Kotlin code snippet:
val list = listOf(1, 2, 3, 4, 5)
val chunks = list.chunked(0)
println(chunks)
medium
A. listOf cannot be used with chunked
B. chunked size cannot be zero
C. Missing import for chunked function
D. drop should be used instead of chunked

Solution

  1. Step 1: Understand chunked parameter requirements

    The chunked(size) function requires a positive integer size greater than zero.
  2. Step 2: Analyze the code

    Using chunked(0) is invalid and will throw an IllegalArgumentException.
  3. Final Answer:

    chunked size cannot be zero -> Option B
  4. Quick Check:

    chunked size > 0 [OK]
Hint: chunked size must be positive, never zero [OK]
Common Mistakes:
  • Using zero or negative chunk size
  • Assuming chunked works like drop
  • Ignoring runtime exceptions
5. Given a list val data = listOf(1, 2, 3, 4, 5, 6, 7), which Kotlin expression produces a list of chunks of size 3, but only for the last 6 elements?
hard
A. data.drop(1).chunked(3)
B. data.take(6).chunked(3)
C. data.chunked(3).drop(1)
D. data.chunked(3).take(2)

Solution

  1. Step 1: Identify last 6 elements

    Using drop(1) removes the first element, leaving last 6 elements [2,3,4,5,6,7].
  2. Step 2: Chunk the remaining list

    Calling chunked(3) on [2,3,4,5,6,7] splits it into [[2,3,4], [5,6,7]].
  3. Final Answer:

    data.drop(1).chunked(3) -> Option A
  4. Quick Check:

    drop(1) then chunked(3) = last 6 in chunks [OK]
Hint: Drop first, then chunk to get last elements in groups [OK]
Common Mistakes:
  • Using take instead of drop for last elements
  • Chunking before dropping
  • Miscounting chunk sizes
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard