From 6d6b8c86372a130a57f8c9deb98feabcfc3ee05d Mon Sep 17 00:00:00 2001 From: chayan das <110921638+Chayandas07@users.noreply.github.com> Date: Fri, 13 Dec 2024 23:42:46 +0530 Subject: [PATCH] Create Sorted and Rotated Minimum --- Sorted and Rotated Minimum | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Sorted and Rotated Minimum 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; + } +};