fork download
  1. fun findMinMax(array: List<Int>): Pair<Int,Int> {
  2. var min = array[0]
  3. var max = array[0]
  4.  
  5. for (el in array) {
  6. if (el < min) {
  7. min = el
  8. } else if (el > max) {
  9. max = el
  10. }
  11. }
  12.  
  13. return Pair(min, max)
  14. }
  15.  
  16. fun main() {
  17. val array = listOf(3, 6, 1, 9, 10, 4, -4, 6, 12, 5, 11)
  18.  
  19. val (min, max) = findMinMax(array)
  20.  
  21. println("Minimum: $min, Maximum: $max")
  22. }
Success #stdin #stdout 0.1s 42380KB
stdin
Standard input is empty
stdout
Minimum: -4, Maximum: 12