`{"id":"4b5d1c3d-3a67-4cd7-81e1-381ba4bc58f9","name":"Find Rotation Count","description":"1. Given an ascending sorted rotated array arr of distinct integers of size N. \r\n2. The array is right rotated K times. \r\n3. Your task is to find the value of K.","inputFormat":"Input is managed for you","outputFormat":"Output is managed for you","constraints":"1 &lt;= N &lt;=10^5\r\n1 &lt;= arr[i] &lt;= 10^7","sampleCode":{"cpp":{"code":"#include <iostream>\n#include <vector>\n\nusing namespace std;\n\nint findRotationCount(vector<int> &arr){\n // write your code here\n}"},"java":{"code":"import java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static int findRotationCount(int[]arr) {\r\n //write your code here\r\n return 0;\r\n }\r\n\r\n public static void main(String[]args) {\r\n //input work\r\n Scanner scn = new Scanner(System.in);\r\n int n = scn.nextInt();\r\n\r\n int[]arr = new int[n];\r\n for(int i = 0 ; i < n; i++) {\r\n arr[i] = scn.nextInt();\r\n }\r\n\r\n int ans = findRotationCount(arr);\r\n System.out.println(ans);\r\n }\r\n}"},"python":{"code":"def main():\r\n pass\r\nif_name_=='__main__':\r\n main()"}},"points":10,"difficulty":"easy","sampleInput":"6\r\n5 6 1 2 3 4","sampleOutput":"2","questionVideo":"https://www.youtube.com/embed/JUYjIZjz6js","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"cb36811c-9cd7-4d80-aa52-ae9b8409862a","name":"Searching And Sorting For Intermediate","slug":"searching-and-sorting-for-intermediate-10001","type":0},{"id":"fbf3ec87-e67a-40c4-a0d6-d7d0fe396999","name":"Find Rotation Count","slug":"find-rotation-count","type":1}],"next":{"id":"2897b677-3da4-4ac6-a00d-2a8e40568d1d","name":"Find Rotation Count","type":3,"slug":"find-rotation-count"},"prev":{"id":"819c30be-4818-4c57-bf02-0c821c9a4733","name":"Count Inversions MCQ","type":0,"slug":"count-inversions-mcq"}}}`

# Find Rotation Count

1. Given an ascending sorted rotated array arr of distinct integers of size N. 2. The array is right rotated K times. 3. Your task is to find the value of K.

`{"id":"4b5d1c3d-3a67-4cd7-81e1-381ba4bc58f9","name":"Find Rotation Count","description":"1. Given an ascending sorted rotated array arr of distinct integers of size N. \r\n2. The array is right rotated K times. \r\n3. Your task is to find the value of K.","inputFormat":"Input is managed for you","outputFormat":"Output is managed for you","constraints":"1 &lt;= N &lt;=10^5\r\n1 &lt;= arr[i] &lt;= 10^7","sampleCode":{"cpp":{"code":"#include <iostream>\n#include <vector>\n\nusing namespace std;\n\nint findRotationCount(vector<int> &arr){\n // write your code here\n}"},"java":{"code":"import java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static int findRotationCount(int[]arr) {\r\n //write your code here\r\n return 0;\r\n }\r\n\r\n public static void main(String[]args) {\r\n //input work\r\n Scanner scn = new Scanner(System.in);\r\n int n = scn.nextInt();\r\n\r\n int[]arr = new int[n];\r\n for(int i = 0 ; i < n; i++) {\r\n arr[i] = scn.nextInt();\r\n }\r\n\r\n int ans = findRotationCount(arr);\r\n System.out.println(ans);\r\n }\r\n}"},"python":{"code":"def main():\r\n pass\r\nif_name_=='__main__':\r\n main()"}},"points":10,"difficulty":"easy","sampleInput":"6\r\n5 6 1 2 3 4","sampleOutput":"2","questionVideo":"https://www.youtube.com/embed/JUYjIZjz6js","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"cb36811c-9cd7-4d80-aa52-ae9b8409862a","name":"Searching And Sorting For Intermediate","slug":"searching-and-sorting-for-intermediate-10001","type":0},{"id":"fbf3ec87-e67a-40c4-a0d6-d7d0fe396999","name":"Find Rotation Count","slug":"find-rotation-count","type":1}],"next":{"id":"2897b677-3da4-4ac6-a00d-2a8e40568d1d","name":"Find Rotation Count","type":3,"slug":"find-rotation-count"},"prev":{"id":"819c30be-4818-4c57-bf02-0c821c9a4733","name":"Count Inversions MCQ","type":0,"slug":"count-inversions-mcq"}}}`

Editor

# Find Rotation Count

easy

1. Given an ascending sorted rotated array arr of distinct integers of size N. 2. The array is right rotated K times. 3. Your task is to find the value of K.

## Constraints

1 <= N <=10^5 1 <= arr[i] <= 10^7

## Format

### Input

Input is managed for you

### Output

Output is managed for you

## Example

Sample Input

```.css-23h8hz{color:inherit;font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;}6 5 6 1 2 3 4```

### Sample Output

`.css-3oaykw{color:var(--chakra-colors-active-primary);font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;font-family:Monospace;}2`

Question Video

Discussions

Show Discussion

Related Resources