You are viewing a single comment's thread. Return to all comments →
Kotlin
fun maxMin(k: Int, arr: Array): Int { var sortedArray = arr.sorted() var result: Int? = null
for(i in 0 until sortedArray.size - k - 1) { var diff = sortedArray[i + k - 1] - sortedArray[i] if(result == null) { result = diff } else { if(result > diff) { result = diff } } } return result ?: 0
}
Seems like cookies are disabled on this browser, please enable them to open this website
Max Min
You are viewing a single comment's thread. Return to all comments →
Kotlin
fun maxMin(k: Int, arr: Array): Int { var sortedArray = arr.sorted() var result: Int? = null
}