Home > Mobile >  Why this code doesn't work in Kotlin Playground or other IDEs?
Why this code doesn't work in Kotlin Playground or other IDEs?

Time:03-28

import kotlin.collections.maxByOrNull
import kotlin.test.*

fun main() {
    var inputArray = mutableListOf(3, 6, -2, -5, 7, 3)
    solution(inputArray)
}
fun solution(inputArray: MutableList<Int>): Int {
  return inputArray.zipWithNext(Int::times).maxOrNull() ?: 0
}

I tried to test this answer in my browser but I can't.

CodePudding user response:

Your code is working but you are not using the result of solution method.

fun main() {
    var inputArray = mutableListOf(3, 6, -2, -5, 7, 3)
    val output = solution(inputArray)

    // do something with output. At least print it to see
    println("output is $output") // output is 21
}

fun solution(inputArray: MutableList<Int>): Int {
  return inputArray.zipWithNext(Int::times).maxOrNull() ?: 0
}
  • Related