diff --git a/Sorted and Rotated Minimum b/Sorted and Rotated Minimum new file mode 100644 index 0000000..a422bf0 --- /dev/null +++ b/Sorted and Rotated Minimum @@ -0,0 +1,19 @@ +class Solution { + public: + int findMin(vector& arr) { + // complete the function here + int n = arr.size(); + if(n == 1) + { + return arr[0]; + } + for(int i = 0; i < n; i++) + { + if(arr[(i-1+n)%n] > arr[i] && arr[i] < arr[(i+1)%n]) + { + return arr[i]; + } + } + return -1; + } +};