Challenge - 5 Problems
Lambda Mastery
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 lambda expression?
Consider the following Kotlin code using a lambda. What will it print?
Kotlin
val numbers = listOf(1, 2, 3, 4) val doubled = numbers.map { it * 2 } println(doubled)
Attempts:
2 left
💡 Hint
The map function applies the lambda to each element.
✗ Incorrect
The lambda { it * 2 } doubles each number in the list, so the output is [2, 4, 6, 8].
🧠 Conceptual
intermediate2:00remaining
Why do lambdas support functional programming in Kotlin?
Which statement best explains why lambdas enable a functional style in Kotlin?
Attempts:
2 left
💡 Hint
Think about how functions can be used in functional programming.
✗ Incorrect
Functional programming treats functions as first-class citizens. Lambdas let you pass functions around easily.
🔧 Debug
advanced2:00remaining
What error does this Kotlin code with lambda cause?
What error will this Kotlin code produce when run?
val list = listOf(1, 2, 3)
val result = list.filter { it > 1 }
.map { it.toString() }
.reduce { acc, s -> acc + s }
println(result)
Kotlin
val list = listOf(1, 2, 3) val result = list.filter { it > 1 } .map { it.toString() } .reduce { acc, s -> acc + s } println(result)
Attempts:
2 left
💡 Hint
Check what filter and map produce before reduce.
✗ Incorrect
Filter keeps 2 and 3, map converts to strings "2" and "3", reduce concatenates to "23".
❓ Predict Output
advanced2:00remaining
What is the output of this Kotlin code using lambdas and sequences?
What will this Kotlin code print?
val seq = sequenceOf(1, 2, 3, 4)
val result = seq.filter { it % 2 == 0 }
.map { it * it }
.toList()
println(result)
Kotlin
val seq = sequenceOf(1, 2, 3, 4) val result = seq.filter { it % 2 == 0 } .map { it * it } .toList() println(result)
Attempts:
2 left
💡 Hint
Filter keeps even numbers, map squares them.
✗ Incorrect
Filter keeps 2 and 4, map squares them to 4 and 16, so output is [4, 16].
🚀 Application
expert2:00remaining
How many items are in the resulting list after this Kotlin lambda chain?
Given this Kotlin code, how many items are in the final list?
val data = listOf("apple", "banana", "cherry", "date")
val filtered = data.filter { it.length > 5 }
val mapped = filtered.map { it.uppercase() }
val result = mapped.drop(1)
println(result.size)
Kotlin
val data = listOf("apple", "banana", "cherry", "date") val filtered = data.filter { it.length > 5 } val mapped = filtered.map { it.uppercase() } val result = mapped.drop(1) println(result.size)
Attempts:
2 left
💡 Hint
Count items with length > 5, then drop the first.
✗ Incorrect
Only "banana" and "cherry" have length > 5 (2 items). Dropping 1 leaves 1 item.