Find How Many Times Array is Rotated
Learning 1D Array Binary Search DSA practice problem on Onlearn.
Difficulty: easy.
Topics: Find the number of rotations in a rotated sorted array, Arrays, Binary Search, Linear Search, Rotated Sorted Array, Time Complexity, Space Complexity, complexity analysis, binary search, array properties, finding elements, search algorithms, array traversal, Sorted & Rotated Arrays, Peak & Minimum Element Finding, Array Traversal & Indexing.
Given an integer array arr of size N, sorted in ascending order (with distinct values). The array has been rotated between 1 to N times. Your task is to find how many times the array has been rotated. Input Specification: An integer array arr. Output Specification: An integer representing the number of times the array has been rotated. Constraints: The array elements are distinct. The array is sorted in ascending order before rotation. The array is rotated at least once and at most N times. Examples: Example 1: Input: arr = [4,5,6,7,0,1,2,3] Result: 4 Explanation: The original array should be [0,1,2,3,4,5,6,7]. The array has been rotated 4 times. Example 2: Input: arr = [3,4,5,1,2] Result: 3 Explanation: The original array should be [1,2,3,4,5]. The array has been rotated 3 times.