The most asked Kotlin interview questions with structured answers — a quick answer, a clear explanation and working code for each. Covers basics for freshers through advanced, scenario and coding questions for experienced developers.
Updated November 2026 Reviewed by Abhishek Kumar 120 min read
Quick answerKotlin is a modern, statically-typed programming language that runs on the JVM. It is designed to be concise, safe, interoperable with Java, and pragmatic.
Statically-typed: Type checking at compile time
Concise: Less boilerplate than Java
Null safety: Built-in null safety features
Interoperable: 100% compatible with Java
Multi-platform: JVM, JS, Native
Kotlin
// Hello World in Kotlinfunmain() {
println("Hello, World!")
}
Quick answerLambda expressions are anonymous functions that can be treated as values. They are widely used in functional programming and collections.
Syntax: { x -> x * x }
it keyword: { it * 2 } for single parameter
Higher-order: Functions taking lambdas
Function reference: ::functionName
Return: Last expression is the return value
Kotlin
// Lambda Expressions in Kotlin// Basic lambdaval square: (Int) -> Int = { x -> x * x }
val square2 = { x: Int -> x * x }
// Lambda with itval doubled = { x: Int -> x * 2 }
val doubled2: (Int) -> Int = { it * 2 }
// Higher-order functionsfunperformOperation(x: Int, y: Int, operation: (Int, Int) -> Int): Int {
return operation(x, y)
}
// Lambda with multiple linesval complexOperation = { x: Int ->
val y = x * 2
y + 10
}
// Function referencefunmultiply(x: Int, y: Int) = x * y
val multiplyRef = ::multiply
// Returning lambda from functionfungetOperation(type: String): (Int, Int) -> Int {
returnwhen (type) {
"add" -> { a, b -> a + b }
"subtract" -> { a, b -> a - b }
else -> { _, _ -> 0 }
}
}
// Usage
println(square(5))
println(performOperation(10, 20, { x, y -> x * y }))
val add = getOperation("add")
println(add(5, 3))
// Type Aliases in Kotlin// Type alias for function typetypealias Operation = (Int, Int) -> Inttypealias StringPredicate = (String) -> Boolean// Type alias for complex typestypealias UserMap = Map<String, User>
typealias ResultCallback = (Result<String>) -> Unit// Usageval add: Operation = { a, b -> a + b }
val multiply: Operation = { a, b -> a * b }
funexecute(op: Operation, a: Int, b: Int): Int {
return op(a, b)
}
typealias User = Pair<String, Int>
val users: UserMap = mapOf(
"user1" to Pair("Alice", 25),
"user2" to Pair("Bob", 30)
)
// Type alias for nested classesclassOuter {
innerclassInnertypealias InnerAlias = Inner
}
// Usage
println(execute(add, 5, 3))
println(execute(multiply, 5, 3))
println(users["user1"]?.first)
Quick answerHigher-order functions are functions that take other functions as parameters or return functions as results.
Parameter: fun operate(op: (Int, Int) -> Int)
Return: fun getMultiplier(): (Int) -> Int
Function composition: compose(f, g)
Callbacks: Used in event handling
Functional programming: Core concept in FP
Kotlin
// Higher-Order Functions in Kotlin// Function that takes a function as parameterfunapplyOperation(a: Int, b: Int, operation: (Int, Int) -> Int): Int {
return operation(a, b)
}
// Function that returns a functionfungetMultiplier(factor: Int): (Int) -> Int {
return { it * factor }
}
// Function compositionfun<A, B, C>compose(f: (B) -> C, g: (A) -> B): (A) -> C {
return { x -> f(g(x)) }
}
// Higher-order function with multiple lambdasfunprocess(
value: Int,
transform: (Int) -> Int,
filter: (Int) -> Boolean
): Int? {
returnif (filter(value)) transform(value) elsenull
}
// Usage with lambdaval result = applyOperation(10, 20) { a, b -> a + b }
println(result)
val double = getMultiplier(2)
println(double(5)) // 10val square = { x: Int -> x * x }
val addTen = { x: Int -> x + 10 }
val squareThenAddTen = compose(addTen, square)
println(squareThenAddTen(5)) // 35// Using with named functionfunadd(a: Int, b: Int) = a + b
val result2 = applyOperation(10, 20, ::add)
println(result2)
Quick answerCoroutines are lightweight threads for asynchronous programming in Kotlin. They provide structured concurrency without the overhead of threads.
Quick answerCalculate factorial using recursion or iteration.
Recursive: if (n <= 1) 1 else n * factorial(n-1)
Iterative: Loop from 2 to n
Edge cases: 0! = 1, handle negatives
Performance: Iterative is faster
Kotlin
// Factorialfunfactorial(n: Int): Long {
returnif (n <= 1) 1else n.toLong() * factorial(n - 1)
}
println(factorial(5)) // 120// Iterative versionfunfactorialIterative(n: Int): Long {
var result = 1Lfor (i in2..n) {
result *= i
}
return result
}
Quick answerCalculate Fibonacci numbers using recursion, iteration, or memoization.
Recursive: if (n <= 1) n else fib(n-1) + fib(n-2)
Iterative: Loop with variables
Memoization: Cache results
Complexity: O(2^n) recursive, O(n) iterative
Kotlin
// Fibonaccifunfibonacci(n: Int): Int {
returnif (n <= 1) n else fibonacci(n - 1) + fibonacci(n - 2)
}
println(fibonacci(8)) // 21// Iterative versionfunfibonacciIterative(n: Int): Int {
var a = 0var b = 1for (i in2..n) {
val temp = a + b
a = b
b = temp
}
returnif (n > 0) b else a
}
Quick answerFind missing number using formula n*(n+1)/2 - sum.
Formula: total - sum(arr)
XOR method: XOR all numbers and indices
Edge cases: Empty array, missing first or last
Complexity: O(n) time, O(1) space
Kotlin
// Find missing numberfunfindMissing(arr: IntArray): Int {
val n = arr.size + 1val total = n * (n + 1) / 2val sum = arr.sum()
return total - sum
}
println(findMissing(intArrayOf(1, 2, 4, 5, 6))) // 3
Quick answerCalculate sum using sum() or manual iteration.
Built-in: arr.sum()
Manual: var sum = 0; for (num in arr) sum += num
Reduce: arr.reduce { acc, i -> acc + i }
Empty array: Returns 0
Kotlin
// Sum of arrayfunsumArray(arr: IntArray): Int {
return arr.sum()
}
println(sumArray(intArrayOf(1, 2, 3, 4, 5))) // 15// Manual implementationfunsumArrayManual(arr: IntArray): Int {
var sum = 0for (num in arr) {
sum += num
}
return sum
}
Quick answerDeep clone objects by recursively copying all nested structures.
Method: Recursive copying
Maps: Copy entries recursively
Lists: Copy elements recursively
Limitations: May not handle all edge cases
Kotlin
// Deep clone objectfun<T>deepClone(obj: T): T {
returntry {
@Suppress("UNCHECKED_CAST")when (obj) {
is Map<*, *> -> {
val map = mutableMapOf<Any, Any?>()
obj.forEach { (key, value) ->
map[key] = deepClone(value)
}
map as T
}
is List<*> -> {
val list = mutableListOf<Any?>()
obj.forEach { item ->
list.add(deepClone(item))
}
list as T
}
is MutableMap<*, *> -> deepClone(obj.toMap())
is MutableList<*> -> deepClone(obj.toList())
else -> obj
}
} catch (e: Exception) {
obj
}
}
dataclassUser(val name: String, val address: Address)
dataclassAddress(val city: String, val zip: String)
val original = User("Alice", Address("NYC", "10001"))
val cloned = deepClone(original)
// Note: This will copy the entire object structure
Quick answerPipe composes functions from left to right.
Method: pipe(fns...)(value)
Implementation: Reduce with function application
Use case: Function composition
Direction: Left to right
Kotlin
// Pipe functionfun<T>pipe(vararg fns: (T) -> T): (T) -> T {
return { value ->
var result = value
for (fn in fns) {
result = fn(result)
}
result
}
}
val double: (Int) -> Int = { it * 2 }
val addTen: (Int) -> Int = { it + 10 }
val square: (Int) -> Int = { it * it }
val process = pipe(double, addTen, square)
println(process(5)) // (5*2+10)^2 = 400
Implementation: ReduceRight with function application
Use case: Function composition
Direction: Right to left
Kotlin
// Compose functionfun<T>compose(vararg fns: (T) -> T): (T) -> T {
return { value ->
var result = value
for (fn in fns.reversed()) {
result = fn(result)
}
result
}
}
val process2 = compose(square, addTen, double)
println(process2(5)) // (5*2+10)^2 = 400
Quick answerEnsure a function is called only once.
Method: Use a flag and closure
Implementation: Track if called
Use case: Initialization
Thread safety: Not needed in single-threaded
Kotlin
// Once functionfun<T>once(fn: () -> T): () -> T {
var called = falsevar result: T? = nullreturn {
if (!called) {
called = true
result = fn()
}
result as T
}
}
val initialize = once {
println("Initialized")
mapOf("id" to 1, "name" to "App")
}
println(initialize()) // Prints "Initialized"
println(initialize()) // Returns cached result
Quick answerThrottle with leading edge executes at most once per time period.
Method: Track last call time
Implementation: Execute if enough time passed
Use case: Scroll events, resize
Difference: Leading vs trailing edge
Kotlin
// Throttle with leading edgefunthrottleLeading(delayMs: Long, fn: () -> Unit): () -> Unit {
var lastCall = 0Lreturn {
val now = System.currentTimeMillis()
if (now - lastCall >= delayMs) {
lastCall = now
fn()
}
}
}
Kotlin is a modern, statically typed programming language developed by JetBrains. It is fully interoperable with Java and is the preferred language for Android app development.
Why is Kotlin preferred for Android development?
Kotlin offers concise syntax, null safety, extension functions, coroutines, better type inference, and seamless Java interoperability, making Android development faster and safer.
What are coroutines in Kotlin?
Coroutines are lightweight threads that simplify asynchronous and concurrent programming while reducing callback complexity and improving performance.
What is null safety in Kotlin?
Null safety is a Kotlin feature that helps prevent NullPointerException by distinguishing nullable and non-nullable types at compile time.
What are data classes in Kotlin?
Data classes are special classes used to store data. Kotlin automatically generates equals(), hashCode(), toString(), copy(), and component functions.
What is Jetpack Compose?
Jetpack Compose is Android's modern declarative UI toolkit for building native user interfaces with less code and improved maintainability.
Why are Kotlin interview questions important?
Kotlin interview questions evaluate knowledge of Android development, OOP, functional programming, coroutines, Flow, null safety, collections, and modern software development practices.
Do companies ask Kotlin coding interview questions?
Yes. Companies hiring Android and backend developers frequently ask Kotlin coding questions involving collections, algorithms, coroutines, object-oriented programming, and system design.
How can I prepare for a Kotlin interview?
Study Kotlin fundamentals, null safety, coroutines, Flow, Android architecture, Jetpack Compose, collections, OOP concepts, and practice solving coding problems and Android development scenarios.
AK
Written and reviewed by Abhishek Kumar
Founder, InterviewPitch · 10+ years in IT. Questions are collected from real interview rounds and refreshed regularly. Spotted an error? Tell us.