LeetCode: Add Two Numbers (in Kotlin)
Using add as a function name seems very ambiguous. The method name used in the Java Solution class from LeetCode seems more appropriate: addTwoNumbers (thereby specifying that the arguments, although not numbers themselves, represent numbers).
You can remove the explicit type specification for var result if you add explicit type arguments to mutableListOf(). I personally find this more readable and less verbose:

var result = mutableListOf&lt;Int&gt;()

You can use start until endExclusive instead of start..endInclusive - 1:

for (i in 0 until Math.max(a.size, b.size))

You can use the slightly shorter getOrElse instead of elementAtOrElse. You can also move trailing lambda arguments out of parentheses:

val sum = a.getOrElse(i) { 0 } + b.getOrElse(i) { 0 } + remainder

You can use an overloaded operator for adding elements to a mutable list:

result += if (remainder &gt;= 1) sum - 10 else sum

I wouldn't use remainder &gt;= 1 or remainder &gt; 0 because it makes it appear that remainder can be greater than 1 which is not true. I recommend using remainder == 1.


Altogether:

fun addTwoNumbers(a: IntArray, b: IntArray): Iterable&lt;Int&gt; {
    val result = mutableListOf&lt;Int&gt;()
    var remainder = 0
    for (i in 0 until Math.max(a.size, b.size)) {
        val sum = a.getOrElse(i) { 0 } + b.getOrElse(i) { 0 } + remainder
        remainder = if (sum &gt;= 10) 1 else 0
        result += if (remainder == 1) sum - 10 else sum
    }
    if (remainder == 1) result.add(1)
    return result
}


However, the "problem" specified in LeetCode does not use arrays which are very different from linked lists. If you convert the Java code it provides you would get the following:

/**
 * Definition for singly-linked list.
 * class ListNode internal constructor(internal var `val`: Int) {
 *     internal var next: ListNode? = null
 * }
 */
class Solution {
    fun addTwoNumbers(l1: ListNode, l2: ListNode): ListNode {

    }
}


Solving such a problem should result in a very different solution than what you've arrived at.