`{"id":"9e5b0913-2f4b-4a7e-af56-22a0ed0eaa78","name":"Pivot In Sorted And Rotated Array","description":"1. You are given an array(arr) of distinct integers, which is sorted and rotated around an unknown point.\r\n2. You have to find the smallest element in O(logN) time-complexity","inputFormat":"An Integer N \r\narr1\r\narr2..\r\nn integers","outputFormat":"The smallest element","constraints":"1 &lt;= N &lt;= 10000\r\n-10^9 &lt;= arr[i] &lt;= 10^9","sampleCode":{"cpp":{"code":"#include <bits/stdc++.h>\nusing namespace std;\nvoid input(vector<int> &arr)\n{\n for (int i = 0; i < arr.size(); i++)\n {\n cin >> arr[i];\n }\n}\nint findpivot(vector<int> &arr)\n{\n //write your code here\n}\nint main()\n{\n int n;\n cin >> n;\n vector<int> vec(n, 0);\n input(vec);\n int pivot = findpivot(vec);\n cout << pivot;\n return 0;\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static int findPivot(int[] arr) {\r\n // write your code here\r\n }\r\n\r\n public static void main(String[] args) throws Exception {\r\n Scanner scn = new Scanner(System.in);\r\n int n = scn.nextInt();\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 int pivot = findPivot(arr);\r\n System.out.println(pivot);\r\n }\r\n\r\n}"},"python":{"code":"def findpivot(arr):\n #write your code here\n \nn=int(input());\narr=[];\nfor i in range(0,n):\n val=int(input());\n arr.append(val);\npivot=findpivot(arr);\nprint(pivot);"}},"points":10,"difficulty":"easy","sampleInput":"9\r\n15\r\n16\r\n19\r\n21\r\n23\r\n24\r\n1\r\n2\r\n12","sampleOutput":"1","questionVideo":"https://www.youtube.com/embed/vF7gk4iaklA?end=125","hints":[],"associated":[{"id":"166f53a2-33f4-4a79-b1d7-501a87b5646c","name":"Time Complexiety of Binary-Search:","slug":"time-complexiety-of-binary-search","type":4},{"id":"2b30c0fc-77a7-4d37-ad55-d5dc3b613c15","name":"Time Complexiety of Linear-Search:","slug":"time-complexiety-of-linear-search","type":4},{"id":"385e6ee5-871c-410c-965c-df3ee6b9cf55","name":"Space Complexiety of Linear-Search:","slug":"space-complexiety-of-linear-search","type":4},{"id":"8122d4d3-a5d7-4b71-8e89-3bde2cffad20","name":"Space Complexiety of Binary-Search:","slug":"space-complexiety-of-binary-search","type":4}],"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":"8e3abac7-a5ab-4090-abd1-b26ef8b53d70","name":"Time and Space Complexity","slug":"time-and-space-complexity","type":0},{"id":"23290752-278f-46de-8060-c028fef9cb72","name":"Pivot In Sorted And Rotated Array","slug":"pivot-in-sorted-and-rotated-array","type":1}],"next":{"id":"8f0f40ac-4220-4b70-a306-552186fc9a9a","name":"Pivot in a sorted and Rotated array","type":3,"slug":"pivot-in-a-sorted-and-rotated-array"},"prev":{"id":"8dfb6ac8-d52c-426e-b995-d9a1022d22d6","name":"Target Sum Pair-1","type":3,"slug":"target-sum-pair-1"}}}`

# Pivot In Sorted And Rotated Array

1. You are given an array(arr) of distinct integers, which is sorted and rotated around an unknown point. 2. You have to find the smallest element in O(logN) time-complexity

`{"id":"9e5b0913-2f4b-4a7e-af56-22a0ed0eaa78","name":"Pivot In Sorted And Rotated Array","description":"1. You are given an array(arr) of distinct integers, which is sorted and rotated around an unknown point.\r\n2. You have to find the smallest element in O(logN) time-complexity","inputFormat":"An Integer N \r\narr1\r\narr2..\r\nn integers","outputFormat":"The smallest element","constraints":"1 &lt;= N &lt;= 10000\r\n-10^9 &lt;= arr[i] &lt;= 10^9","sampleCode":{"cpp":{"code":"#include <bits/stdc++.h>\nusing namespace std;\nvoid input(vector<int> &arr)\n{\n for (int i = 0; i < arr.size(); i++)\n {\n cin >> arr[i];\n }\n}\nint findpivot(vector<int> &arr)\n{\n //write your code here\n}\nint main()\n{\n int n;\n cin >> n;\n vector<int> vec(n, 0);\n input(vec);\n int pivot = findpivot(vec);\n cout << pivot;\n return 0;\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static int findPivot(int[] arr) {\r\n // write your code here\r\n }\r\n\r\n public static void main(String[] args) throws Exception {\r\n Scanner scn = new Scanner(System.in);\r\n int n = scn.nextInt();\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 int pivot = findPivot(arr);\r\n System.out.println(pivot);\r\n }\r\n\r\n}"},"python":{"code":"def findpivot(arr):\n #write your code here\n \nn=int(input());\narr=[];\nfor i in range(0,n):\n val=int(input());\n arr.append(val);\npivot=findpivot(arr);\nprint(pivot);"}},"points":10,"difficulty":"easy","sampleInput":"9\r\n15\r\n16\r\n19\r\n21\r\n23\r\n24\r\n1\r\n2\r\n12","sampleOutput":"1","questionVideo":"https://www.youtube.com/embed/vF7gk4iaklA?end=125","hints":[],"associated":[{"id":"166f53a2-33f4-4a79-b1d7-501a87b5646c","name":"Time Complexiety of Binary-Search:","slug":"time-complexiety-of-binary-search","type":4},{"id":"2b30c0fc-77a7-4d37-ad55-d5dc3b613c15","name":"Time Complexiety of Linear-Search:","slug":"time-complexiety-of-linear-search","type":4},{"id":"385e6ee5-871c-410c-965c-df3ee6b9cf55","name":"Space Complexiety of Linear-Search:","slug":"space-complexiety-of-linear-search","type":4},{"id":"8122d4d3-a5d7-4b71-8e89-3bde2cffad20","name":"Space Complexiety of Binary-Search:","slug":"space-complexiety-of-binary-search","type":4}],"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":"8e3abac7-a5ab-4090-abd1-b26ef8b53d70","name":"Time and Space Complexity","slug":"time-and-space-complexity","type":0},{"id":"23290752-278f-46de-8060-c028fef9cb72","name":"Pivot In Sorted And Rotated Array","slug":"pivot-in-sorted-and-rotated-array","type":1}],"next":{"id":"8f0f40ac-4220-4b70-a306-552186fc9a9a","name":"Pivot in a sorted and Rotated array","type":3,"slug":"pivot-in-a-sorted-and-rotated-array"},"prev":{"id":"8dfb6ac8-d52c-426e-b995-d9a1022d22d6","name":"Target Sum Pair-1","type":3,"slug":"target-sum-pair-1"}}}`

Editor

# Pivot In Sorted And Rotated Array

easy

1. You are given an array(arr) of distinct integers, which is sorted and rotated around an unknown point. 2. You have to find the smallest element in O(logN) time-complexity

## Constraints

1 <= N <= 10000 -10^9 <= arr[i] <= 10^9

## Format

### Input

An Integer N arr1 arr2.. n integers

### Output

The smallest element

## 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;}9 15 16 19 21 23 24 1 2 12```

### 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;}1`

Question Video

Discussions

Show Discussion

Related Resources