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

1 Answer

0 votes
using System;

public class Program
{
	private static int countRotations(int[] arr) {
		int min = arr[0], min_index = 0;
		int size = arr.Length;

		for (int i = 0; i < size; i++) {
			if (min > arr[i]) {
				min = arr[i];
				min_index = i;
			}
		}

		return min_index;
	}

	public static void Main(string[] args)
	{
		int[] arr = new int[] {23, 19, 15, 4, 6, 8, 9, 11};

		Console.Write(countRotations(arr));
	}
}





/*
run:
 
3
 
*/

 



answered Nov 21, 2023 by avibootz
...