How to count the number of times sorted array with distinct integers are circularly rotated in TypeScript

1 Answer

0 votes
function countRotations(arr: number[]) {
    let min: number = arr[0], min_index = 0;
    let size: number = arr.length;
     
    for (let i: number = 0; i < size; i++) {
        if (min > arr[i]) {
            min = arr[i];
            min_index = i;
        }
    }
     
    return min_index;
}
         
const arr: number[] = [23, 19, 15, 4, 6, 8, 9, 11];
 
console.log(countRotations(arr));
 
 
 
 
/*
run:
 
3
 
*/

 



answered Nov 22, 2023 by avibootz
...