Daniel Schmidt
03/18/2020, 4:31 PMIndex of Maximum
doesn't mention that the last index of the largest element should be returned.
Source: https://try.kotlinlang.org/#/Examples/Problems/Index%20of%20Maximum/Index%20of%20Maximum.kt
Original description:
/*
* Your task is to implement the indexOfMax() function so that it returns
* the index of the largest element in the array, or null if the array is empty.
*/
A simple solution which fulfills the description but fails for the last two test cases:
fun indexOfMax(a: IntArray): Int? {
return if(a.isEmpty()) null else a.indexOf(a.max()!!)
The last two test cases contain the largest value multiple times and expect that the indexOfMax
return the last index of the larget value.