Dsa
Binary Search
Medium
Number of Rotations in Sorted Array
You are given a rotated sorted array. Write a function to find the number of rotations in the array. The number of rotations is defined as the number of times the sorted array is cut and rotated. For example, in an array [4, 5, 6, 7, 0, 1, 2], it has been rotated 4 times.
Input format:
- The first line contains an integer n (1 ≤ n ≤ 10^6), the size of the array.
- The second line contains n space-separated integers representing the rotated sorted array.
Output format:
- Print a single integer, the number of times the array is rotated.
Example:
Input:
7
4 5 6 7 0 1 2
Output:
4
Key concepts
binary_searcharrayrotation
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now