Resume

Interview prep

The follow-up ladder

Interviews don't stop at the first question. Each card starts with one question, then climbs through the follow-ups an interviewer asks next. Try each step out loud before you open the answers.

8 ladders · 2 "what does this print?" cards · Follows the roadmap

Kotlin and DSA basics

  1. Ladder · 4 stepsJuniorNull safety
    1. QWhat is the difference between ?. and !! in Kotlin?

      Show answers

      Junior answer

      ?. calls the member only if the value is not null, otherwise it gives null. !! throws if the value is null.

      Senior answer

      ?. turns a nullable chain into a nullable result, so the null case stays visible in the type. !! says "I know better than the compiler" and moves the failure to runtime as a NullPointerException.

    Read the full answer with code →
    How did you do?
  2. Ladder · 3 stepsMidAny, Unit and Nothing
    1. QWhat are Any, Unit and Nothing?

      Show answers

      Junior answer

      Any is like Object, Unit is like void, Nothing means no value.

      Senior answer

      Any is the root of every non-null type. Unit is a real type with one value, used when a function returns nothing useful. Nothing has no values at all: a function returning Nothing never returns normally.

    How did you do?
  3. Ladder · 4 stepsJuniorData class vs regular class
    1. QWhat does the data keyword give you?

      Show answers

      Junior answer

      equals, hashCode, toString and copy.

      Senior answer

      equals, hashCode, toString, copy and componentN functions for destructuring, all generated from the primary constructor properties.

    How did you do?
  4. What does this print?JuniorData class vs regular class

    What does this print?

    data class User(val name: String) {
        var age = 0
    }
    
    val a = User("Asha").apply { age = 30 }
    val b = User("Asha").apply { age = 40 }
    println(a == b)
    println(a)
    Show output
    true
    User(name=Asha)

    age is declared in the class body, not the primary constructor, so equals and toString ignore it.

    How did you do?
  5. Ladder · 3 stepsMidSealed class vs enum
    1. QWhen would you use a sealed class instead of an enum?

      Show answers

      Junior answer

      When you need more than constants.

      Senior answer

      An enum has a fixed set of single instances that all share the same shape. A sealed class has a fixed set of types, and each type can carry its own data, like Loading, Error(message) and Success(items).

    How did you do?
  6. Ladder · 3 stepsSeniorValue classes
    1. QWhat is a value class?

      Show answers

      Junior answer

      A class that wraps one value.

      Senior answer

      @JvmInline value class UserId(val value: String) gives a distinct type at compile time. At runtime it usually compiles down to the plain String, so you get type safety without an extra object.

    How did you do?
  7. Ladder · 4 stepsMidlazy vs lateinit
    1. QWhat is the difference between lazy and lateinit?

      Show answers

      Junior answer

      lazy is for val and runs the block on first use. lateinit is for var that you assign later.

      Senior answer

      lazy is a delegate: the value is computed once, on first read, and can't change. lateinit is a promise that a var will be assigned before it's read, which suits values set by a framework, like injected fields or test setup.

    How did you do?
  8. Ladder · 4 stepsSeniorinline and reified
    1. QWhat does inline do?

      Show answers

      Junior answer

      It makes the function faster.

      Senior answer

      The compiler copies the function body and its lambda arguments into each call site. That removes the lambda object and the call, which matters for small higher-order functions called often.

    How did you do?
  9. Ladder · 3 stepsMidCollections vs Sequences
    1. QWhat is the difference between a List chain and a Sequence chain?

      Show answers

      Junior answer

      Sequences are lazy.

      Senior answer

      A List chain runs each step over the whole list and builds a new list each time. A Sequence passes each element through all the steps before the next element, and only when a terminal operation like toList or first runs.

    How did you do?
  10. What does this print?MidCollections vs Sequences

    What does this print?

    val result = listOf(1, 2, 3)
        .asSequence()
        .map { println("map $it"); it * 2 }
        .filter { println("filter $it"); it > 2 }
        .first()
    println(result)
    Show output
    map 1
    filter 2
    map 2
    filter 4
    4

    A Sequence sends one element through every step before the next. first() stops at the first match, so 3 is never mapped.

    How did you do?

Your marks stay in this browser only. "Shaky first" brings the cards you marked shaky or no idea to the top.