ecem
ecem

Reputation: 3

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

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.

Upvotes: 0

Views: 294

Answers (1)

ocos
ocos

Reputation: 2244

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
}

Upvotes: 2

Related Questions