Please comment understood and give us a like if you got everything :)
@vishnusiddarth7953
Жыл бұрын
mass
@sudhanshushekhar4222
Жыл бұрын
Understood
@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
11 ай бұрын
East or west. Striver is the best
@aladdinstudios2735
9 ай бұрын
I came only for Minimum in Rotated Sorted Array so why I would seen previews video #striver ?
@HananTariq-ws9wd
11 ай бұрын
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
7 ай бұрын
Pucha kisine?
@travelbest5623
Ай бұрын
Ab ji*@d recruitment mai bhi dsa poochne lage kya? 😂😂
@shivajirao999
3 ай бұрын
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
3 ай бұрын
Abe easy hai ye upper ke 3 phele se kiye hue the esiliyee btw good
@Rahul_Mongia
3 ай бұрын
@@ravikr3463
@ayushpatidar5778
Жыл бұрын
The way you cover each and every edge case is amazing. Understood everything 👍
@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
9 ай бұрын
bro where did u do dsa in java from?
@abhaymaurya9
3 ай бұрын
the same exact code i was able to write down without even watching your lecture first , kudos to u🙌❣
@snigdhadatta4702
2 ай бұрын
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.
@Cubeone11
Ай бұрын
I used to think that neetcode gives the best explanation, but after watching this playlist i changed my thoughts.
@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
Жыл бұрын
this does not cover all the cases
@ayushmittal9666
10 ай бұрын
I think if we remove the condition of checking if(a[low]
@kiranmoura2974
Жыл бұрын
For duplicates I think the whole code will remain same only the optimized part will be changed as if (a[low]==a[mid] and a[low]==a[high]) {ans=min(ans,arr[low]); Low++; High--; Continue; Please check whether it is correct or not .
@anshuman-sl9du
Жыл бұрын
yeah its correct dude !! thanx i was stuck there 🤖
@omkarshendge5438
2 ай бұрын
yea you are right so basically the duplicates case arises when there is like mid low high all three are same so basically this case is same as search in a rotated sorted array 2 right? there also this case has rose.
@AyushEditz-hs6pf
27 күн бұрын
This works as well: first check if the right side of mid is sorted then check of left side. int findMin(vector& nums) { int ans=INT_MAX; int low=0; int high=nums.size()-1; while(low
@parth2439
7 ай бұрын
Understood, the last optimisation was great !!
@luvdhamija5157
9 ай бұрын
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]
@Aks-47
8 ай бұрын
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
@Rohitkumar-bx8ne
4 ай бұрын
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
@himanshusingh1899
Ай бұрын
Best DSA course on you tube.
@RAJSINGH-mr7hq
Жыл бұрын
Understood! Awesome explanation as always, thank you soooo much for your effort!!
@sukhjattana5887
Жыл бұрын
u unfolded the mysterious binary search....thank you!!!
@tanishkthakur9965
4 ай бұрын
got it , understood everything
@MansiBansalc
6 ай бұрын
YOU ARE AN AMAZING TEACHER! THANKYOU FOR EXISTING!
@sayak4636
Жыл бұрын
Hometask(LC-154):- class Solution { public: int findMin(vector& nums) { int s=0; int e=nums.size()-1;int ans=INT_MAX; while(s
@floatingpoint7629
Жыл бұрын
if interviewers ask you to modify it so it returns the index, this won't work
@6mahine_mein_google
Жыл бұрын
@@floatingpoint7629 In duplicates we cant return index because it would have no meaning consider [3,3,3,3,3] this as example, minimum here is 3 but index is not defined because index can be anything here. Please correct me if i am wrong
@floatingpoint7629
Жыл бұрын
@@6mahine_mein_google if all are duplicates then array is not a rotated one. it is guaranteed that array is at least rotated once
@saiyyamagrawal765
28 күн бұрын
int findMin(vector& nums) { int n = nums.size(); int low = 0 , high=n-1; while(low
@sunnykumarpal5087
Жыл бұрын
Bhaiya your explanation is relay fabulous. It makes hard concepts easily understandable to us. Thank you bhaiya for helping us in dsa.
@hengulrajsaikia9227
Ай бұрын
The mid will point to the minimum element at least once
@nirajaya5
2 ай бұрын
Great explanation! Thank you so much.
@jagdishkhetre4515
11 ай бұрын
Understood...Awesome Binary search Playlist.. 👏
@TrinmoyDutta
6 ай бұрын
while(low
@rahulsidhu5945
Жыл бұрын
Understood.. Awesome Binary search Playlist..😍
@per.seus._
Жыл бұрын
UNDERSTOOD❤
@adarshkumarrao3478
Жыл бұрын
UNDERSTOOD
@Anshydv3
Жыл бұрын
understood ! the best explanation bhaiya , you are hero and a real gem❤
@yossihadad8558
9 ай бұрын
amazing!
@aps2129
2 ай бұрын
Amazing explanation!!!!!
@HappyHumbleHopefulHelpKey
Ай бұрын
Understood ❤
@RagaviSathiyamoorthy
10 ай бұрын
Sir completed the problem which you gave as homework 😇😇
@dayashankarlakhotia4943
Жыл бұрын
Good explanation. Explanation in depth
@ashishpradhan6250
4 ай бұрын
understood
@harshitjaiswal9439
8 ай бұрын
Understood!
@kritikamanglam
Жыл бұрын
Understood :)
@KaranBisht-p5d
Ай бұрын
Understood!!
@lakshgangwani3014
Жыл бұрын
if my array is [2, 4, 1, 2], In this case wouldn't the optimised code would give the answer 2 (because of the if condition (ar[low]
@kc9049
Жыл бұрын
your array has a duplicate element, and the code is for the unique element.
@sruthimajhi5610
2 ай бұрын
If the left part of the array is unsorted then it obviously contains the smallest element, right? Also, in an other case where the right part of the array is unsorted then it obviously contains the smallest element, right? So mostly the element lies in the unsorted part if one part is sorted and the other is not regardless of whether the minimum element is present in the sorted part or not, am I correct?
@DeepakPatel-d5v
5 ай бұрын
Thanks a lot Bhaiya
@venkynani9892
10 ай бұрын
My thought process: int low=0; int high=arr.length-1; int min=arr[high]; while(lowmin) { low=mid+1; } else{ min=arr[mid]; high=mid-1; } } return min;
@hakunamatata-nl4js
4 ай бұрын
Thank you
@alheraahmad5481
25 күн бұрын
understood!
@piyushroy3278
3 ай бұрын
understood sir. Huge kudos to you :)
@rutujashelke4208
Ай бұрын
Understood
@rushidesai2836
4 ай бұрын
Great question!
@nikhilthulaseedharan1525
Жыл бұрын
Java Solution for LC 154 with Duplicates: public int findMin(int[] nums) { int n=nums.length; int low=0; int high=n-1; int ans=Integer.MAX_VALUE; while(low
@rahulkumarjena8252
6 ай бұрын
@takeUForward , can you also add find pivot element in Sorted Roatated array .i am unable to find it out in your playlist
@Shunya_Advait
Жыл бұрын
Understood Sir. Thank You Sir 👌👌
@md_seraj786_
6 ай бұрын
understood all clear ❤
@JothiprakashThangaraj
2 ай бұрын
understood, thanks a lot!
@nihalsingh6233
11 ай бұрын
Understood!!!
@NazeerBashaShaik
5 ай бұрын
Understood, thank you.
@dank7044
10 ай бұрын
did this on my own in one go.
@ayush52905
6 ай бұрын
@takeUforward at 05:10 , what if we always look for the unsorted part ? Everytime we can check if mid's left and right is smaller than mid and if not then move to the unsorted part . This makes sense right ?
@kushiksahu1983
6 ай бұрын
Exactly I thought in the same way but couldn't figure out the way. I thought to first check for the sorted part if it exist in right side of the mid i.e a[mid]
@Diptanjank
11 ай бұрын
Understood !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@khalasianiket816
3 ай бұрын
understood❤
@aumrudhlalkumar5487
2 ай бұрын
Thanks
@samuelfrank1369
11 ай бұрын
Understood, Thanks a lot
@abhaythakur2597
Жыл бұрын
very well explained
@soumyadeepghosh4428
11 ай бұрын
sir can you please solve Leetcode 154 in this approach with some modifications ?
@ganjinaveen7338
Жыл бұрын
Super level understood
@selviraghavi-jp4ep
5 ай бұрын
Minimum in rotated sorted array with duplicates my solution : class Solution { public int findMin(int[] arr) { int low = 0; int high=arr.length - 1; int min = Integer.MAX_VALUE; while(low
@saswatrath4646
5 ай бұрын
it's correct
@saswatrath4646
5 ай бұрын
thanks for sharing I was looking to match code with someone
@selviraghavi-jp4ep
5 ай бұрын
Welcome bro :)@@saswatrath4646
@AdityaKumar-eb9ff
Жыл бұрын
nice explanation
@naazfilz
Жыл бұрын
We can Still find the Pivot in the Unsorted array by this method class Solution { public: int findMin(vector& arr) { int n = arr.size(); if (n == 1) return arr[0]; if (n == 2) { if (arr[0] > arr[1]) return arr[1]; else return arr[0]; } int low = 0; int high = arr.size() - 1; while (low
@soumiyamuthuraj3516
3 ай бұрын
awesome
@abhay9994
11 ай бұрын
Thank you.
@Shivi32590
3 ай бұрын
thanku
@pulkitgupta669
8 ай бұрын
Understood ❤❤
@vageshnp6792
3 ай бұрын
tq
@pratikshah3005
Жыл бұрын
CFBR
@karthiknair1430
Жыл бұрын
my approach is to find the pivot ans then +1 will always be the lowest is this correct?
@sayakghosh5104
Жыл бұрын
Understood!
@ghj7275
7 ай бұрын
If anyone finds the link to practice problem of this with duplicate elements in the array, please share.
@KCOYASH
Жыл бұрын
Understood :) thanks
@hallupandet228
Жыл бұрын
Understood💯
@manishnimbal6192
Жыл бұрын
Minimum is always be found in unsorted portion of an rotated sorted array .. so can we run our loop within unsorted portion . Ex { 6,7,0,1,2,3,4} here mid is at 1 and right portion is sorted so can we run our loop from low
@manishnimbal6192
Жыл бұрын
Means after eleminating right portion we have left 6,7,0 and minimum is present in it 🫣🫣
@pabitradas9024
Жыл бұрын
Understood bhaiya
@SiddharthPandey-qe2lk
7 ай бұрын
Understood🎉😮
@PrathuJoshi
Жыл бұрын
Understood
@Gaurav_Tripathi_
10 ай бұрын
Understood..!!
@NitinPeace
Жыл бұрын
Understood👍
@soumi6720
6 ай бұрын
understood!!
@adityasingh5239
Жыл бұрын
int findMin(vector& arr) { int n=arr.size(); int l=0,h=n-1,mid; while(l=arr[h]) l=mid+1; else h=mid; } return arr[mid]; } passes all testcases on leetcode with 100% beat
@factorialfacts9353
Жыл бұрын
1 3 3
@abhinavdixit5829
Жыл бұрын
why this code is not working in coding Ninja? Can someone tell the testcase it won't work class Solution { public: int findMin(vector& arr) { int s=0; int e=arr.size()-1; int mid=s+(e-s)/2; int mini=5001; while(s
@kadurkaz4691
Жыл бұрын
Love u man
@praveen_meena
Жыл бұрын
understood bhaiya
@prathamsoni5625
7 ай бұрын
UnderStood
@Lucifer0872
Жыл бұрын
Understood dada
@yashkalia2311
9 ай бұрын
Goated
@bhuoneparmar5098
Жыл бұрын
gotcha!!
@MAHESHAITBECS
2 ай бұрын
striver
@MohammadEhshan-ve6uz
Ай бұрын
My code is working without using edge case condition is that correct? int minimumElementInRotatedArray2(int arr[],int n){ //Note:It also contain duplicates elements //Que:Find the smallest element in this array int low=0,high=n-1,ans=INT_MAX; while(low
@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
Жыл бұрын
Thanks brother 🙏🏾
@cinime
Жыл бұрын
Understood! Awesome explanation as always, thank you soooo much for your effort!!
Пікірлер: 375