BS-6. Minimum in Rotated Sorted Array

  Рет қаралды 148,260

take U forward

take U forward

Күн бұрын

Problem Link: bit.ly/41My2dR
Notes/C++/Java/Python codes:takeuforward.org/data-structu...
We have solved the problem, and we have gone from brute force and ended with the most optimal solution. Every approach's code has been written in the video itself. Also, we have covered the algorithm with intuition.
Full Course: bit.ly/tufA2ZYt
You can follow me across social media, all my handles are below:
Linkedin/Instagram/Telegram: linktr.ee/takeUforward
0:00 Introduction of Course

Пікірлер: 351
@takeUforward
@takeUforward Жыл бұрын
Please comment understood and give us a like if you got everything :)
@vishnusiddarth7953
@vishnusiddarth7953 Жыл бұрын
mass
@sudhanshushekhar4222
@sudhanshushekhar4222 Жыл бұрын
Understood
@ersoumyajitpan7205
@ersoumyajitpan7205 Жыл бұрын
************ more optimized ************ int findMin(vector& nums){ int left = 0, right = nums.size() - 1; while (left < right) { int mid = left + (right - left) / 2; if (nums[mid] > nums[right]) { left = mid + 1; } else { right = mid; } } return nums[left]; }
@adil_k
@adil_k 9 ай бұрын
East or west. Striver is the best
@aladdinstudios2735
@aladdinstudios2735 7 ай бұрын
I came only for Minimum in Rotated Sorted Array so why I would seen previews video #striver ?
@shivajirao999
@shivajirao999 2 ай бұрын
the feeling of writing the exact same code by your own without even looking at the lecture is insane, ALL thanks to your level of explanation
@ravikr3463
@ravikr3463 Ай бұрын
Abe easy hai ye upper ke 3 phele se kiye hue the esiliyee btw good
@Rahul_Mongia
@Rahul_Mongia Ай бұрын
@@ravikr3463
@abhishekverma7604
@abhishekverma7604 Жыл бұрын
guys, this is one of the most important question if u r preparing for amazon and adobe.. hell they asked it a lot in previous 6 months according to Leetcode stats..
@animeshshaw388
@animeshshaw388 10 ай бұрын
Thanks brother 🙏🏾
@akshitbhasin7322
@akshitbhasin7322 8 ай бұрын
The fact that you acknowledged the problem of having different formats in binary search deserve a like. keep up the good work!
@ayushpatidar5778
@ayushpatidar5778 Жыл бұрын
The way you cover each and every edge case is amazing. Understood everything 👍
@iWontFakeIt
@iWontFakeIt Жыл бұрын
man what an explanation ! I saw several solutions on leetcode discuss but couldn't understand all of it, some if else conditions were going above my head, but you made it so clear I did code it myself both leetcode 153 and 154 with AC solutions
@HananTariq-ws9wd
@HananTariq-ws9wd 9 ай бұрын
Understood!! Hi I'm a Pakistani and I study at US. I really like your DSA playlist and recommend it to everyone. Thank you so much for your effort.
@AmanSingh-wr6mj
@AmanSingh-wr6mj 5 ай бұрын
Pucha kisine?
@vishious14
@vishious14 6 ай бұрын
6 minutes into the video, I was able to deduce the whole logic as soon as I understood the approach !!!!!! Amazing content !!!!!!
@abhaymaurya9
@abhaymaurya9 Ай бұрын
the same exact code i was able to write down without even watching your lecture first , kudos to u🙌❣
@user-cx4mh7sc2j
@user-cx4mh7sc2j 8 ай бұрын
I'm really blessed to watch and learn the concept form you striver and i'm solving the problems now without referring the solutions. Thanks a lot.
@shrirambalaji2915
@shrirambalaji2915 Жыл бұрын
just watched like 7 min and understood the solution and what i am missing out thanks man you are awesome
@surendhar.v4952
@surendhar.v4952 Жыл бұрын
If hurts the most , when you realize this easy question took you more than 2 hour and failed several time while in the test cases below 5 when you submit in leetcode. I did a course on java in youtube from a famous youtuber an year ago. I took a short break of two months for my semster exam and other activities. I can remind that I solved a similar type of question in an year ago. But now , I am struggling to do a easy problem like this.... Taking a break, even it is small gets your mind out of the programming mode.
@vaibhavvm4147
@vaibhavvm4147 7 ай бұрын
bro where did u do dsa in java from?
@RAJSINGH-mr7hq
@RAJSINGH-mr7hq Жыл бұрын
Understood! Awesome explanation as always, thank you soooo much for your effort!!
@harshitgarg2820
@harshitgarg2820 11 ай бұрын
Striver sir plz start a series for strings to simplify strings for us just like you did with the other topics🙏
@snigdhadatta4702
@snigdhadatta4702 20 күн бұрын
I was solving this for the first time , was struggling because everytime was giving me runtime error and guess what i lerally watched the first 10 mins only infinite times , because my dumb brain was just not convincing myself that how is this done, at 3pm night i passed this that too in 0ms time without seeing your written code 😭😭😭😭😭. It was giving me stress because i haven't been able to pass a single solution that day so i really needed anything to get accepted just to boost my morale . Thanks striver.
@parth2439
@parth2439 5 ай бұрын
Understood, the last optimisation was great !!
@paragroy5359
@paragroy5359 7 ай бұрын
Thanks a lot for making such videos. Your content is amazing. Keep on doing the great work
@SahitiDantuluri
@SahitiDantuluri Ай бұрын
I have gone through some solutions to this problem and able to understand but if I try to recollect and code it later I would be a little confused. But your explanation and approach is so detailed and very easy to understand that I am able to solve it on my own without any confusion (even after many days). Thanks a lot!!
@mehulthuletiya497
@mehulthuletiya497 Жыл бұрын
00:38 Problem statement 01:21 Brute-force approach 01:38 Optimal approach 06:30 Dry-run 10:35 Pseudocode 12:57 Code 13:20 Optimised version : If you want try to do then 15:04 Code 15:27 Complexity
@andycharlie3255
@andycharlie3255 9 ай бұрын
woow bro, this is crazy, legendary explanation, hats off man
@Anshydv3
@Anshydv3 Жыл бұрын
understood ! the best explanation bhaiya , you are hero and a real gem❤
@sukhjattana5887
@sukhjattana5887 Жыл бұрын
u unfolded the mysterious binary search....thank you!!!
@dayashankarlakhotia4943
@dayashankarlakhotia4943 Жыл бұрын
Good explanation. Explanation in depth
@Cubeone11
@Cubeone11 2 күн бұрын
I used to think that neetcode gives the best explanation, but after watching this playlist i change my thoughts.
@MansiBansalc
@MansiBansalc 4 ай бұрын
YOU ARE AN AMAZING TEACHER! THANKYOU FOR EXISTING!
@Manasidas99
@Manasidas99 10 ай бұрын
Understood sir thank you very much, sir. Your teaching style is really amazing. I hope I will crack my interview.
@sunnykumarpal5087
@sunnykumarpal5087 Жыл бұрын
Bhaiya your explanation is relay fabulous. It makes hard concepts easily understandable to us. Thank you bhaiya for helping us in dsa.
@nirajaya5
@nirajaya5 13 күн бұрын
Great explanation! Thank you so much.
@akkipinky9194
@akkipinky9194 4 ай бұрын
Thanks for the incredible knowledge u give us...understood!!
@aps2129
@aps2129 24 күн бұрын
Amazing explanation!!!!!
@AnmolGupta-oj4lm
@AnmolGupta-oj4lm Жыл бұрын
Understood Very Well!
@dipingrover1970
@dipingrover1970 3 ай бұрын
amazing explanation . thanks a lot
@UserUser-tn8tv
@UserUser-tn8tv 6 ай бұрын
Understood. Very Good Explanation
@jagdishkhetre4515
@jagdishkhetre4515 10 ай бұрын
Understood...Awesome Binary search Playlist.. 👏
@aliakbaransaria3-925
@aliakbaransaria3-925 11 ай бұрын
Very good explanation Thank you
@rahulsidhu5945
@rahulsidhu5945 Жыл бұрын
Understood.. Awesome Binary search Playlist..😍
@hariomtiwari9283
@hariomtiwari9283 9 ай бұрын
Super Explanation 🎉🎉
@namangarg8976
@namangarg8976 10 ай бұрын
Another approach I thought of - -> If left array is sorted, right is unsorted. Then go to right as pivot point can be current element or in right array -> If right is sorted, left is unsorted. Then go to left as pivot point can be current element or in left array -> If both are sorted then break and just compare the ans with arr[low] as complete search space is sorted. int findMin(vector& arr) { int low = 0; int high = arr.size() - 1; int ans = INT_MAX; while(low
@ompandey2911
@ompandey2911 6 ай бұрын
Was wondering, What if I search for target = INT_MIN and keep the code same as the previous video wont the arr[low] be my answer?
@myproject6768
@myproject6768 Жыл бұрын
Absolutely understand ❤
@rushidesai2836
@rushidesai2836 2 ай бұрын
Great question!
@visase2036
@visase2036 Жыл бұрын
Thanks Striver. Adding my thoughts for (duplicates) . If we apply the previous logic of high-- or low++ as the mid and low/high values are equal , we will end up getting the minimum element but that does not gaurentee the no of times array has been rotated . Examples: array=[1,1,2,1,1] , orignal array = [1,1,1,1,2]. The correct answer is 3 (as the element at 0th index has been moved to 3rd index [1,1,2,1,1]). But if we apply the previous logic, the answer would come as 0 as 0th index is the minimum element. To upsolve this, we can do the following : Keep reducing high, untill [high-1] > [high] (2>1). Once you attain this point, high(3rd index) will be the answer.
@floatingpoint7629
@floatingpoint7629 Жыл бұрын
this does not cover all the cases
@ayushmittal9666
@ayushmittal9666 9 ай бұрын
I think if we remove the condition of checking if(a[low]
@md_seraj786_
@md_seraj786_ 4 ай бұрын
understood all clear ❤
@tanishkthakur9965
@tanishkthakur9965 2 ай бұрын
got it , understood everything
@kingbadshah452
@kingbadshah452 5 ай бұрын
thanks striver understood everything
@samuelfrank1369
@samuelfrank1369 10 ай бұрын
Understood, Thanks a lot
@JothiprakashThangaraj
@JothiprakashThangaraj Ай бұрын
understood, thanks a lot!
@NazeerBashaShaik
@NazeerBashaShaik 4 ай бұрын
Understood, thank you.
@kiranmoura2974
@kiranmoura2974 Жыл бұрын
Bahut ache se smgh aaya sir ❤
@abhaythakur2597
@abhaythakur2597 Жыл бұрын
very well explained
@presidenttalks8
@presidenttalks8 5 ай бұрын
Understood👍 thank you sir
@piyushroy3278
@piyushroy3278 Ай бұрын
understood sir. Huge kudos to you :)
@ddevarapaga5134
@ddevarapaga5134 Ай бұрын
Understood perfect bro
@RishabhKumar0094
@RishabhKumar0094 Ай бұрын
understood, for duplicate elements worst case time complexity will be O(n/2).
@NitinKumar-wm2dg
@NitinKumar-wm2dg Жыл бұрын
understood, thank you bhaiya
@Shunya_Advait
@Shunya_Advait 11 ай бұрын
Understood Sir. Thank You Sir 👌👌
@AdityaKumar-eb9ff
@AdityaKumar-eb9ff 10 ай бұрын
nice explanation
@yossihadad8558
@yossihadad8558 7 ай бұрын
amazing!
@KCOYASH
@KCOYASH Жыл бұрын
Understood :) thanks
@UdayGarg
@UdayGarg Жыл бұрын
bro you are amazing litt
@motivationalcomred
@motivationalcomred Жыл бұрын
@striver take case a = [5[L] 1 2[M] 3 4[H]] mid is lesser in both arrays 2
@infernogamer52
@infernogamer52 Жыл бұрын
Understood Bhaiya!
@ganjinaveen7338
@ganjinaveen7338 Жыл бұрын
Super level understood
@mahadishakkhor123
@mahadishakkhor123 4 ай бұрын
Hey god bless you bro❤
@per.seus._
@per.seus._ 11 ай бұрын
UNDERSTOOD❤
@user-or5oz1pk2x
@user-or5oz1pk2x 3 ай бұрын
Thanks a lot Bhaiya
@Rohitkumar-bx8ne
@Rohitkumar-bx8ne 2 ай бұрын
solved without any help with BS, but before solving i have watched the previous two videos of the playlist which helped in developing the thinking skill for solving this problem
@soumi6720
@soumi6720 4 ай бұрын
understood!!
@hallupandet228
@hallupandet228 Жыл бұрын
Understood💯
@rahulreddy3588
@rahulreddy3588 9 ай бұрын
Understood!
@abhay9994
@abhay9994 9 ай бұрын
Thank you.
@GodeDev
@GodeDev 6 ай бұрын
Thank you
@YourCodeVerse
@YourCodeVerse 7 ай бұрын
Understood✅🔥🔥
@bilal_khan8514
@bilal_khan8514 5 ай бұрын
Understood Bhaiya 😃
@rishabh1S
@rishabh1S Жыл бұрын
Understood!!
@senseiAree
@senseiAree 10 ай бұрын
Understood ❤
@shahidullahmuffakir668
@shahidullahmuffakir668 Ай бұрын
Thanks man
@pulkitgupta669
@pulkitgupta669 7 ай бұрын
Understood ❤❤
@sidusaini4658
@sidusaini4658 2 ай бұрын
understood!
@Gaurav_Tripathi_
@Gaurav_Tripathi_ 9 ай бұрын
Understood..!!
@heyOrca2711
@heyOrca2711 20 күн бұрын
Understood! Sir
@user-on3er8zf2n
@user-on3er8zf2n Жыл бұрын
Understood everything
@Aks-47
@Aks-47 7 ай бұрын
slightly lengthier, but core logic is , we need to handle 2 cases where we are uncertain where to move, that was the crux for me, a) mid is less than lo and hi, b) mid greater than lo and hi, if we exclude that , then searching is regular BS, attaching java code for the same int ans = Integer.MAX_VALUE; while(lo
@ANSHUKUMARI-ng4hj
@ANSHUKUMARI-ng4hj 10 ай бұрын
understood sir🙏
@luvdhamija5157
@luvdhamija5157 7 ай бұрын
We know that if it is sorted in nature then arr[low] would always be the minimum number of all. by considering this we can simplify this as following. low=0 high=len(nums)-1 while lownums[high]: low=mid+1 elif nums[low]>nums[mid]: high=mid else: break return nums[low]
@nihalsingh6233
@nihalsingh6233 9 ай бұрын
Understood!!!
@MYMIND252
@MYMIND252 10 ай бұрын
love you bro
@khalasianiket816
@khalasianiket816 Ай бұрын
understood❤
@AmanKumarSharma-de7ft
@AmanKumarSharma-de7ft 11 ай бұрын
int findMin(vector& nums) { int start=0,end=nums.size()-1; while(startnums[end]?start=mid+1:end=mid;} return nums[start];} };
@lakshminarayana5500
@lakshminarayana5500 Жыл бұрын
Understood
@NitinPeace
@NitinPeace Жыл бұрын
Understood👍
@outdoorlove-tq6qw
@outdoorlove-tq6qw 7 ай бұрын
i am learn from you , one day i will cross you 🙇
@kadurkaz4691
@kadurkaz4691 11 ай бұрын
Love u man
@user-cx4mh7sc2j
@user-cx4mh7sc2j 8 ай бұрын
Sir completed the problem which you gave as homework 😇😇
@projectsdb4034
@projectsdb4034 5 ай бұрын
understood SIR
@baibhavghimire3827
@baibhavghimire3827 6 ай бұрын
You beat neetcode on this🎉. Superb dude.
@aishezsingh7004
@aishezsingh7004 12 күн бұрын
I think This is more intutive moving towards unsorted and if sorted move left while(low arr[mid] ) high = mid - 1; else if( arr[mid] > arr[high] ) low = mid + 1; else { ans = min(ans , arr[low] ); break; } } return ans;
@kritikamanglam
@kritikamanglam 11 ай бұрын
Understood :)
@Santosh-up7gk
@Santosh-up7gk 5 ай бұрын
Thank u
@SiddharthPandey-qe2lk
@SiddharthPandey-qe2lk 6 ай бұрын
Understood🎉😮
@pabitradas9024
@pabitradas9024 Жыл бұрын
Understood bhaiya
BS-7. Find out how many times array has been rotated
5:01
take U forward
Рет қаралды 94 М.
BS-4. Search Element in Rotated Sorted Array - I
16:38
take U forward
Рет қаралды 225 М.
Fast and Furious: New Zealand 🚗
00:29
How Ridiculous
Рет қаралды 46 МЛН
Can A Seed Grow In Your Nose? 🤔
00:33
Zack D. Films
Рет қаралды 30 МЛН
Я не голоден
01:00
К-Media
Рет қаралды 9 МЛН
Son ❤️ #shorts by Leisi Show
00:41
Leisi Show
Рет қаралды 9 МЛН
Launching the best DSA Course + Platform
36:29
take U forward
Рет қаралды 115 М.
BS-8. Single Element in Sorted Array
22:16
take U forward
Рет қаралды 135 М.
8 patterns to solve 80% Leetcode problems
7:30
Sahil & Sarra
Рет қаралды 293 М.
Why Do Bubbles Form In Glasses Of Water?
12:33
Joe Scott
Рет қаралды 117 М.
BS-10. Finding Sqrt of a number using Binary Search
17:11
take U forward
Рет қаралды 111 М.
Kadane's Algorithm | Maximum Subarray Sum | Finding and Printing
20:09
take U forward
Рет қаралды 367 М.
The Best Browsers for Privacy and Ad Blocking
8:40
Mental Outlaw
Рет қаралды 33 М.
Fast and Furious: New Zealand 🚗
00:29
How Ridiculous
Рет қаралды 46 МЛН