Given an array in Kotlin, check if it is sorted or not. An array is sorted in natural order when every array element is greater than its previous element.

The trick is to iterate over the array and compare each set of adjacent elements. The array is considered sorted if the first element is less than the second element for every pair of adjacent elements and unsorted otherwise.

Download Code

 
Here’s a recursive procedure for the above code:

Download Code

That’s all about determining whether an array is sorted in Kotlin.