Find Minimum in Rotated Sorted Array | Leetcode 153 Solution | Searching and Sorting

preview_player
Показать описание

NADOS also enables doubt support, career opportunities and contests besides free of charge content for learning. Question Statement:
1. Suppose an array of length n sorted in ascending order is rotated between 1 and n times.
2. Notice that rotating an array [a[0], a[1], a[2], ..., a[n-1]] 1 time results in the array [a[n-1], a[0], a[1], a[2], ..., a[n-2]].
3. Given the sorted rotated array nums of unique elements, return the minimum element of this array.
4. You must write an algorithm that runs in O(log n) time.

Topic: #BinarySearch #leetcode153 #SearchingAndSorting

Used #DataStructure: #Array

#TimeComplexity: O(log n)

#SpaceComplexity: O(1)

--------------------------------------------------------------

Linked Questions:

---------------------------------------------------------------

----------------------------------------------------------------

#BinarySearch #leetcode153 #SearchingAndSorting #Array #geeksforgeeks



.
.
.
Happy Programming !!! Pep it up 😍🤩
.
.
.
#pepcoding #code #coder #codinglife #programming #coding #java #freeresources #datastrucutres #pepcode #competitive #competitiveprogramming #softwareengineer #engineering #engineer
Рекомендации по теме
Комментарии
Автор

Insane Explanation Di. Dimag hi khol dia.
SALUTE TEAM PEPCODING

SaumyaSharma
Автор

Manisha Mam is the best .Thanks for going through all the possible cases. So grateful mam😃

rosonerri-faithful
Автор

excuse me this is the most brilliant video i have seen so far... mam u deserve every success in world

PrabhdeepSingh-otqy
Автор

I never got these kind of solution highly appreciated mam thanks a lot amazing solution ❤️❤️

rockeykumar
Автор

You are just incredible ma'am!!! Wonderful explanation

SeloniSinha
Автор

thanks maam .... understood how to apply binary search in these type of questions

SuryajyotiDas
Автор

Very nice explanation mam, although question is tricky because of different test cases

GhostRider....
Автор

Very good explanation. Specially that part that why we should take first condition with mid+1 and not with mid-1.
This type of things, help us to understand the whole cases or examples associated with question and if Interviewer try to tweak the question, than also we know how to handle the question.
Thanks alot i am looking for this question and here i got the solution with detailed explaination.
Pepcoding aane wale time m, ek nayi wave leke aayega codders ki.
Thank you pepcoding

abhishekverma
Автор

Good and easy explanation of the intuition.

mayurdluffy
Автор

based on the technique you taught while solving "Searching in a Rotated sorted array, I solved this.
My logic was quite simple,
find the mid, check if the left part of the mid is sorted or not, if yes, then compare the left part's first indexed value with that of res, and assign the minimum there. Otherwise move to the right part.
If the right part is sorted, then compare the right part and do the same.
Here is my python code:

s, e = 0, len(nums)-1
res = float(inf) #very large value
while s<=e:
mid = e-(e-s)//2

if nums[mid]>=nums[s]:
res = min(res, nums[s])
s = mid+1
elif nums[mid]<=nums[e]:
res = min(res, nums[mid])
e = mid-1
return res

sadmanabedin
Автор

This is the best explanation for this question, thanks!!!

harshaggarwal
Автор

Great work. Looking forward to more of these amazing videos. You are the best teacher here after sumeet sir.

akshatdubey
Автор

Awesome explanation. Have covered all side cases. This video helped me a lot. Thanks.

shobhitarya
Автор

Definitely helpful, keep going on ..., Thanks a lot.

masruralam
Автор

Ngl you explained this question way better than summet sir 😆

loserfruit
Автор

FACT : mid will always go to first ele before seocnd when a search range is of/between 2 ele only, so here we know ans exist means a left ele to smallest exist, so we will surely get ele before mid reaches the end ele of array, so we used mid+1 condition first as mid will land on 2last position before it land on last, and answer then may exist on 2last index surely, so mid+1 can be used freely

mickyman
Автор

Great Explanation Madam, please do more videos related to graphs

nithinreddygajjala
Автор

tq pepcoding,
iss playlist m aur kitne question aane baki hai abhi?kindly let us know

theuntoldtree
Автор

1 2 3 4 90 80. 1 < 4 < 80. we can't always compare the extremities?

advik
Автор

Thanks a lot for this great explanation!!

aindrilasaha
join shbcf.ru