top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Find the Rotation Count in Rotated Sorted array

+1 vote
630 views

Find the count k by which array has been rotated in the rotated sorted array. So for example we have sorted array as 2,3,6,12, 15, 18. Now suppose the array is rotated k times ( we don’t know k), such that array becomes 15, 18,2,3,6,12 We have to find K?

posted Apr 29, 2014 by Merry

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+2 votes
 
Best answer

Store the largest element of sorted array in a temp variable before the array is rotated.
Once the array is rotated, find the current index of largest element then k = (array size- 1) - current array index.

answer Apr 29, 2014 by Harshita
Similar Questions
+1 vote

Given 3 sorted array of size x, y, z. what is the minimum time taken to find the kth smallest element in the merged sorted array.

+3 votes

In an "N" element integer sorted array, a particular elements is repeating "(N/2)+1" times. How much time it take to find the repeating element.

+2 votes

1,1,2,2,2,6,6,6,7,7,7,7,7,7,7,8,8,9,9,9

Example:
Input = 1 Output=0 (First index of 1).
Input = 2 Output=2 (First index of 2).
Input = 6 Output= 5 (First index of 6).
Input = 7 Output= 8 (First index of 7).
Input = 8 Output=15 (First index of 8).
Input = 9 Output=17 (First index of 9).

...