This is the best dsa series on RUclips!!!!! My request is to everyone who is reading this comment plz share this playlist with your juniors and friends. You can share with at least one friend.
Bhaiyya aap OP ho pivot wala problem teen baar dekhne ke baad samjh aaya uske baaad toh chize easy kardiye aapne.Thanks bhaiyya having a teacher like you can get me a job in Google.❤❤❤
49:37 "mujhe lag rha hai ki aapko bilkul smjh nhi aa rha", "mujhe pata hai aapko nhi aa rha " "tension na le ," "mujhe pata lg gya aapko smjh nhi aa rha " VERY VERY ACURATE FOR ME AT THIS MOMENT mai shock ho gya laga aamne saamne padh rha hoon.......😊😊
Sir you deserve all good and wealth in this world, because you love other as yourself and you always help and support. You have been a great teacher, lecturer, and a Professor to me, and I fully enjoyed your lectures, you explained everything in detail
pivot you explain is other and array is sorted but in previous lecture you told us to solve a leetcode question 724 in which pivot means this-: The pivot index is the index where the sum of all the numbers strictly to the left of the index is equal to the sum of all the numbers strictly to the index's right.
You deserves millions of subscribers for your hardwork bro. You are way better than code with Harry telusku etc etc. You explains everything twice no one even do it once properly. Hats off to you sir. Keep growing.❤️
Thank you so much bhaiya.. ye series bahut achchi hai jab maine dsa start kiya tha to normal sa question banane mai bhi ghanto lag jate the but abhi apki vajah se aaj maine 3 achche questions 40 min mai kar liye.. thank you so much... ab confidence bhi aa rha hai ki ho jayega dsa
Staying strong with you...14th lecture! No going back Babbar bro... I love the series till now. Especially the optimized way to find mid-value and also these binary search questions are making me think better. I'll comment in the next video. See you then! Regards, Dharrsan
2:30 The way you use colors of Indian flag and explain concepts is soo satisfying. You are contributing a lot to India indirectly by making a big change in Education industry.
Sir two suggestion ..... 1) First one is If possible you give topic time table that which topic you will teach in which day or date so all can atleast prepare the topic understand the topic by themselves and solve some problems related to topic ..... which helps to understand all points that you taught in video 2) And second one is you give all difficulty level question links ( generally medium and hard) and maximum problems of that topic that all can master the topic and solve any problem of that topic in all formats in interview or in CP, or in leetcode and all other platforms....
I think it is not possible because love bhaiya search for topic and possible questions from that topic and make video accordingly. How can you expect that he can provide you dates before.
@@sjcreations2490 No sir ......I think he had some plan in mind what topics that he covered so what his plan related to topic covering , he should give and I am not saying that give 2 months plan day wise but my suggestion is atleast give weekly plan ........ and secondly I think bhaiyaa recorded the session few days before the session upload on RUclips.....
the approach of finding the piovt element is correct and in most o fthe cases it will retrun the correct value, but in inputs like {11,13,15,17}, the pivot will move to index 3 but it is wrong, so aas per me logic we should declare a temp variable outside the loop value 0. after the loop is terminated we will compare the value of temp index with the start index value if the value of the start index is smaller we will return start else we will return temp.. this will help to find the piovt in all cases, whether the array is rotated or not..
31:40 Bhaiya At this timestamp of video , I would suggest try to start an array from [ 1 to n/2 ]. Reason is for any number n , square root of n is always smaller than n/2 ( Corollary Based on popular Theorem ).I don't remember the name of that theorem. This will slightly optimize an algorithm. Example : n = 36 ==> 6 < 18 n = 81. ==> 9 < 40 n = 625 ==> 25 < 312 and so on ..
yes brother, I searched about it and found that the one you mentioned is a corollary of the AM-GM inequality, it states: (m+1)/2 >= sqrt(m) (where m belongs to N)
It has been the best series so far on youtube. This series is really helping me to improve my thinking & logic building skills . Thank you bhaiya...keep it up.
@@yashgupta6574 yes bcoz it is a sorted array so either first element or last element bcome pivoted element so it,s obvious that it would be max or min
First I have completed all DSA series and now conclude this is Greatest ever DSA series to exist on youtube or paid courses. Your contribution will be remembered. You're God of DSA for us🙇♂
in pivot element, if the array is not rotated in edge case then it will return last index that is wrong so we have to compare with last element not first element in array, int findMin(vector& nums) { int start = 0; int end = nums.size()-1; int mid = start+(end-start)/2; while(startnums[nums.size()-1]){ start = mid+1; }else{ end = mid; } mid = start+(end-start)/2; } return start }
if anyone finding 11:23 answer here it is class Solution { public: int pivotIndex(vector& nums) { // accumulate is a stl which is used to addition of array int rs=accumulate(nums.begin(),nums.end(),0); int ls=0; for(int i=0;i
I have watched many DSA series but your course is one of the best series that I have watched till now, thank you so much for putting so much of efforts for us. I wish you keep growing in every aspect of your life ... :), 1 question, does anyone came to know about the 2nd and 3rd approach of Finding an element in rotated sorted array?
The code that he has explained for pivot index only works when array is rotated at least once, if array is not rotated or else it is rotated n times (where n is arr.size() - 1) it will give incorrect answer on leetcode question 153. And to fix this we can write this on very top of our function: if(nums[0]
A better approach for the second question. according to you, the process/flow chart is- 1- finding pivot. 2- apply that target formula and find the portion of the monotonic function. 3-Then apply Binary search to find the index value. according to me. 1- if(key>=arr[0]){ //apply binary in the first segment } else { //apply binary in second segment } I am not an expert on time complexity, just have seen your previous video. but for your approach time complexity should be 1 O(log2^n)+O(log2^n) and for my approach, it should be O(log2^n) P.s I've just started DSA, so correct me if I am wrong.
Edit- I found my mistake. How can I apply binary search in the first or second segment if I dont know the pivot element(i.e. start of second segment and end of the first segment.)
// THis is what i did and it was accepted in leetcode 33 int search(vector& nums, int target) { int s=0; int e=nums.size()-1; int mid=s+(e-s)/2; while(s=nums[0]){ if(nums[mid]>target) e=mid-1; else if(nums[mid]>=nums[0]) s=mid+1; else e=mid-1; } else{ if(nums[mid]=nums[0]) s=mid+1; else e=mid-1; } mid=s+(e-s)/2; } return -1; }
ye jo first question hai pivot element wala usme hum arr[0] se na compare keke balki arr[end] se kare to jada best hoga kyuki hume nhi pta hota ki sorted array kitni baar rotate kia gya hai kya pata vo rotate hoke sirf sorted hi hogya ho jaise ki {11,12,13,14,15} ye array rotate hoke yhi ban gya to arr[0] se hamara ans galat ayega but arr[end] se hamesha shi ayega ....
//finding the target in sorted rotated array using binary search //ex-> A = {7,8,9,10,1} // key = 9 //output -> element found at index 2 //code written by harsh shukla #include using namespace std; int PivotInRotSortArr(int arr[] , int size){ int s = 0 , e = size - 1; while(s arr[mid+1]){ return mid+1; } else if(arr[s]
Thank you so much bhaiya for bringing such a great, full fledged and premium content in free of cost for all of us ❤🙏🙏🙏..... We are putting our effort 👌 💪 🙂 👏 🙌
what did i learn from this lecture 1.how to find pivot element in rotated and sorted array 2. how to find an element in rotated and sorted array 3. how to find the square root of an element 4. how to find the precesion of the square root
Easier way to implement precision using brute force double squareroot(int element, int integerpart, int precision){ double ans=integerpart; double factor=1; for (int i=1; i
Note - For precision part we can make a function and convert the precision int into floating point num.... like 3 gets converted to 0.001 float num = 37; float ans = findSqrt(num); while (true) { if ((ans + 0.01) * (ans + 0.01) < num) { ans += 0.01; } else { break; } } cout
Leaving this comment so that after an year if someone liked this cmmnt i'll be appreciating myself for my hard work. nd surely at that time i'll work in a good MNC. love from ghaziabad bhaiya:)
I am so happy that i solved the square root of n question by myself after understanding the first 2 questions. Thank you so much for this useful lecture
UPDATE GUYZZZZZ...........................Also correct me if i am wrong............the solution for sorted and rotated array can't solved every testcase in the leetcode platform it can solve 133/195 cases.............where array is [ 1 ] ...........target = 1 , output goes -1 but answer expected is 0.......we have to come up with an solution for this edge case....
This solution pases all the test cases int lowerPivot(vector& arr, int size){ int s = 0; int e = size -1; int mid = s + (e - s)/2; while(s < e){ if(arr[mid] >= arr[0]){ s = mid + 1; } else{ e = mid; } mid = s + (e - s)/2; } return s; } int binarySearch(vector& arr, int s , int e, int key){ int start = s; int end = e; int mid = start + (end - start)/2; while(start
My friend tell me about this daa lecture series and now I learning this series for placement this time my second year is about to completed and really thank you bhaiya ❤️❤️❤️❤️
Solution for Search in Sorted Array by splitting in two parts: Approach: 1. Get Pivot 2. If key == arr[pivot] it is the answer 3. if(key>=arr[0]) it lies in first half therefore, s=0, e = pivot-1 4. else, it lies in second half therefore s= mid, e = size-1 5. Now perform BS based on the selected values of e and s. Complexity = O(logn) Code: int getPivot(vector& arr,int n){ int s = 0; int e = n-1; int mid = s + (e-s)/2; while(s=arr[0]){ s= mid+1; }else{ e = mid; } mid = s+(e-s)/2; } return s; } int findPosition(vector& arr, int n, int k) { int pivot = getPivot(arr,n); if(arr[pivot]==k){ return pivot; } int s,e; //splitting array based on pivot element if(k>=arr[0]){ e = pivot-1; s = 0; } else{ e = n-1; s = pivot; } int mid = s + (e-s)/2; while(sk){ e = mid-1; //move left }else{ s = mid+1; } mid = s+(e-s)/2; } return -1; }
Sorry sir , but the question in last video (Find Pivot in an array) was actually a point where left sum = right sum , but in video you are explaining something else . Please clarify this sir .
bro, at that point he means smallest in array. And in leet code question 33, there is definition of pivot where leftSum = rightSum. Hope you understand , that it is only a word that is vary from concept to concept
> The Pivot index** is the index where the sum of all the numbers **strictly** to the left of the index is equal to the sum of all the numbers **strictly** to the index's right. **Pivot element** is the only element in input array ( Which is already a rotated sorted array) which is smaller than it's previous element. A pivot element divided a sorted rotated array into two monotonically increasing array. >
@@arnobbaiga309 bro comparision jo h vo phele hua like jab loop khtm nhi hua h and then jab ekk iteration puri hui uske baad s = 4 , e = 4 hua then loop end hogya
bhaiya wo pivot wale question ka kuch or Matlab dia hua tha leet code pe... find pivot index:- it is a index where sum of all numbers strictly to the left side of the index is equal to the sum of all the no.s strictly to the index's right.Return the leftmost pivot index.
thank you bhaiya..bhot mzza aa rha hai...I observed you are working late night till 5 in the morning😂😂. bhot hard...bhot hard....bs josh thanda na pdne dena
Sir ek logic ye bhi laga sakte he na ki... Apan ne mountain element nikala tha to ager apan last mountain element ka return thoda change ker de to bhi answer aa sakta he na... Jaise ki... ....... return array[start+1]; ....... Isse ye ho ki jo top point hoga uska next element mil jaega Jo ki pivot point hoga...
Sir the code for pivot element is not working for some edge cases such as if the sorted array is rotated by zero or rotated by n whr n being the no of elements in the array is that true or i m doing somewhere wrong.
Bhai really learning a lot from you... Really like your videoes. Now I feel like I am being helped by my elder brother. Thank you so much bhaiya... Just one thing more than 1 hr video ko miss kr rha hu... Thank you so much bhaiya for helping.
bhaiya when we google search and on Leetcode also ..it defines pivot of an array as an index where the sum of all the numbers strictly to the left of the index is equal to the sum of all the numbers strictly to the index's right. can i get some more clarity on pivot of an array .. I'm little confused.
@CodeHelp - by Babbar! Bhaiya, you haven't mentioned the solution of " Q-724>> Find the Pivot Element" yet in leetcode? please, plz make our concept clear regarding that problem.
Rotated Sorted array using the second approach. int search(int* arr, int n, int k) { // Write your code here. int s = 0 , e = n - 1 , mid; while( s k) e = mid -1; else if(k > arr[0] && arr[mid] < k) s = mid + 1; else if(k > arr[0] && arr[mid] > k) e = mid -1; else return mid; } return -1; }
What is the 2nd and 3rd approach for the Searching element in the sorted rotated array? He talks about it at 27:44 in the video. Can anyone please share their approaches?
// search in a sorted rotated array #include using namespace std; int search(vector& nums, int target) { int s=0; int e=nums.size()-1; while(s=nums[0]){ //left side if(target>=nums[s] && targetnums[mid] && target
//Search in a Rotated and Sorted Array #include using namespace std; int search(int a[], int n, int key) { int beg=0, end=n-1, mid; while(beg=a[0]) { if(keykey) end=mid-1; else beg=mid+1; } else if(a[mid]=a[0]) end=mid-1; else if(a[mid]>key) end=mid-1; else beg=mid+1; } } return -1; } int main() { int a[]={7,9,10,1,2,3}; int n=sizeof(a)/sizeof(a[0]); int key=2; cout
We can also add a case like if element is not rotated but sorted then we return it's first element (a leetcode test case) so we can add an if condition like if(arr[0]
Commenting for reach bhaiya, mai abhi 10th mei but I am preparing for INOI, so cp mei c++ aata hai and aapka hi course dekhunga promise. Abhi mai sabmei commenting for reach krta rahunga Love you 3000 babbar bhai ❤️
love form Pakistan Bro, your videos is really helpful for me and my class fellow as I am a university student but your videos means alot to me and my other class fellows. Thank you soo much for this helpfull series
bhaiya pivot element toh vo hota h na jisske left side ke elements ak sum right side ke elements ke sum ke equal ho....but aapne toh pure array me minimum element ko hi pivot bataya h...toh pivot ki koi pele se defination nhi hoti ky?...aur ky pivot element question to question vary krte h?
Seach element in rotated sorted array has 3 approach 1) discussed in lecture involving pivot 2) comparison with arr[0] and directly binary search But I am confused with the 3rd approach of which bhaiya was giving hint Please clarify 😅
One doubt in sqre rot question - Can we not find precision again with binary search. For example- if we want precision of 2, then s=0.01 and e= 0.99 and then we can calculate via binary search.
Do make sure to visit Relevel: relvl.co/tv0v :-)
Bhiya scope of data science par ek video bano please
🔥🔥
bhaiya vo square root wale me Baar Baar SIGTERM output para hai kya cru
#love bahiya yeh code studio vala square root question ka code dedo usme kuch case big no vale submit krne pe fail ho rhe h
ruclips.net/video/tAQIKe0UGH4/видео.html
This is the best dsa series on RUclips!!!!!
My request is to everyone who is reading this comment plz share this playlist with your juniors and friends. You can share with at least one friend.
chal bhai age gyan mt pe***
Another approach to find pivot in an array !!!
int getpivot(int arr[],int n){
int s = 0;
int e = n-1;
int mid = s + (e-s)/2;
while(s
if mid is the pivoted element?
Bhaiyya aap OP ho pivot wala problem teen baar dekhne ke baad samjh aaya uske baaad toh chize easy kardiye aapne.Thanks bhaiyya having a teacher like you can get me a job in Google.❤❤❤
49:37
"mujhe lag rha hai ki aapko bilkul smjh nhi aa rha",
"mujhe pata hai aapko nhi aa rha "
"tension na le ,"
"mujhe pata lg gya aapko smjh nhi aa rha "
VERY VERY ACURATE FOR ME AT THIS MOMENT
mai shock ho gya laga aamne saamne padh rha hoon.......😊😊
bhai yehi likne ke liye aya tha scroll krta niche...these lines were Fr
Sir you deserve all good and wealth in this world, because you love other as yourself and you always help and support. You have been a great teacher, lecturer, and a Professor to me, and I fully enjoyed your lectures, you explained everything in detail
Difference of Love babbar and Aman dattarwal course is :-
Aman dattarwal course made by FAANG people's and love babbar course made to crack FAANG
Do not forget that he has also worked in amazon for 2 years
pivot you explain is other and array is sorted but in previous lecture you told us to solve a leetcode question 724 in which pivot means this-:
The pivot index is the index where the sum of all the numbers strictly to the left of the index is equal to the sum of all the numbers strictly to the index's right.
exactly..the one he used is for rotated array question
exactly i don't know what type of pivot is in the video it not also work for any leetcode
questions
@@1hokage8 no not working
You deserves millions of subscribers for your hardwork bro. You are way better than code with Harry telusku etc etc. You explains everything twice no one even do it once properly. Hats off to you sir. Keep growing.❤️
ok
@@sagartaak4017 😂😂😂🤦
@@lovishmittal4859 jukh ke rhena padega
Thank you so much bhaiya.. ye series bahut achchi hai jab maine dsa start kiya tha to normal sa question banane mai bhi ghanto lag jate the but abhi apki vajah se aaj maine 3 achche questions 40 min mai kar liye.. thank you so much... ab confidence bhi aa rha hai ki ho jayega dsa
aapne yhi question 40 min mai kiye ki dusre que 40 min mai kiye
please reply
Staying strong with you...14th lecture!
No going back Babbar bro...
I love the series till now.
Especially the optimized way to find mid-value and also these binary search questions are making me think better. I'll comment in the next video. See you then!
Regards,
Dharrsan
placement hogyi?
placement hogyi?
@@lalitsharma3137 haa 5000 rupay mahina. maine hi internship di h isko
@@understanding-why 😂😂
can u tell me why comparision takes place in 15;40 _ as s=4 and end =4 while statement doesnt satisfy here
2:30 The way you use colors of Indian flag and explain concepts is soo satisfying. You are contributing a lot to India indirectly by making a big change in Education industry.
may be he didn't intend that!
@@arjunyadav-kt5jr
padle bhai bharat sarkaar free ki naukri nahi degi....khud hi karna h jo karna h
Sir two suggestion ..... 1) First one is If possible you give topic time table that which topic you will teach in which day or date so all can atleast prepare the topic understand the topic by themselves and solve some problems related to topic ..... which helps to understand all points that you taught in video 2) And second one is you give all difficulty level question links ( generally medium and hard) and maximum problems of that topic that all can master the topic and solve any problem of that topic in all formats in interview or in CP, or in leetcode and all other platforms....
Yes✌️✌️✌️✌️✌️✌️✌️
I think it is not possible because love bhaiya search for topic and possible questions from that topic and make video accordingly. How can you expect that he can provide you dates before.
@@sjcreations2490 No sir ......I think he had some plan in mind what topics that he covered so what his plan related to topic covering , he should give and I am not saying that give 2 months plan day wise but my suggestion is atleast give weekly plan ........ and secondly I think bhaiyaa recorded the session few days before the session upload on RUclips.....
i just type the problem in google and leetcode in it and the first result is the leetcode problem. Hope this helps.
ruclips.net/video/tAQIKe0UGH4/видео.html
the approach of finding the piovt element is correct and in most o fthe cases it will retrun the correct value, but in inputs like {11,13,15,17}, the pivot will move to index 3 but it is wrong, so aas per me logic we should declare a temp variable outside the loop value 0. after the loop is terminated we will compare the value of temp index with the start index value if the value of the start index is smaller we will return start else we will return temp.. this will help to find the piovt in all cases, whether the array is rotated or not..
in 15:47 start and end both pointing at 4, so the loop stop here only as in while condition (s
Do I find any solution for that
31:40 Bhaiya At this timestamp of video , I would suggest try to start an array from [ 1 to n/2 ]. Reason is for any number n , square root of n is always smaller than n/2 ( Corollary Based on popular Theorem ).I don't remember the name of that theorem. This will slightly optimize an algorithm.
Example : n = 36 ==> 6 < 18
n = 81. ==> 9 < 40
n = 625 ==> 25 < 312 and so on ..
yes brother, I searched about it and found that the one you mentioned is a corollary of the AM-GM inequality, it states:
(m+1)/2 >= sqrt(m) (where m belongs to N)
Hii.. This will be true for all numbers except 2... because sqroot of 2 is 1.414, which is greater than its half (1).
Thanks.
@@deepbhatia_1511 also it won't hold true for 3 as well, as root 3= 1.732 and 3/2=1.5 ....
It has been the best series so far on youtube. This series is really helping me to improve my thinking & logic building skills .
Thank you bhaiya...keep it up.
is it correct that pivot element is min or max element of an array?
@@yashgupta6574 yes bcoz it is a sorted array so either first element or last element bcome pivoted element so it,s obvious that it would be max or min
First I have completed all DSA series and now conclude this is Greatest ever DSA series to exist on youtube or paid courses. Your contribution will be remembered. You're God of DSA for us🙇♂
Congratulations for the completion bro 🎉❤
are you placed
in pivot element, if the array is not rotated in edge case then it will return last index that is wrong so we have to compare with last element not first element in array,
int findMin(vector& nums) {
int start = 0;
int end = nums.size()-1;
int mid = start+(end-start)/2;
while(startnums[nums.size()-1]){
start = mid+1;
}else{
end = mid;
}
mid = start+(end-start)/2;
}
return start
}
If it is not rotated then use binary search algorithm since it is increasing Order
We all are with you bhaiya. please be constant till the end. Your way of teaching is excellent.
if anyone finding 11:23 answer here it is
class Solution {
public:
int pivotIndex(vector& nums) {
// accumulate is a stl which is used to addition of array
int rs=accumulate(nums.begin(),nums.end(),0);
int ls=0;
for(int i=0;i
I have watched many DSA series but your course is one of the best series that I have watched till now, thank you so much for putting so much of efforts for us. I wish you keep growing in every aspect of your life ... :),
1 question, does anyone came to know about the 2nd and 3rd approach of Finding an element in rotated sorted array?
well the second approach can be done by using the if condition nums[start]
ATTENDANCE MARKED, VISITED RELEVEL, MADE NOTES, SOLVED QUESTIONS, LIKED THE VIDEO, EXITED WITH A SMILE.
Truly Great series sir, You have truly helped me overcome my fear of DSA.
Thank You very Much.
apke ka course bhai sab courses s unique is liye h kyuki apne har topic p bohot sare question karaye h , jo kisi ne nhi karaye , best than paid course
BEST TEACHER AWARD GOES TO YOU BHAIYA😇
Explaining T.C. and S.C. of all the problems after soln. will be very helpful
The code that he has explained for pivot index only works when array is rotated at least once, if array is not rotated or else it is rotated n times (where n is arr.size() - 1) it will give incorrect answer on leetcode question 153.
And to fix this we can write this on very top of our function: if(nums[0]
we can also use this
int start=0,end=size-1,mid;
while(startarr[end])
start=mid+1;
else if(arr[mid]
faced this exact problem. thanks.
the code for this problem( search in rotated sort array) given on gihub gives compilation error...is it with everyone?
For that you can use the following condition in the beginning itself:-
if(arr[0]
TLE aarha
A better approach for the second question.
according to you, the process/flow chart is-
1- finding pivot.
2- apply that target formula and find the portion of the monotonic function.
3-Then apply Binary search to find the index value.
according to me.
1- if(key>=arr[0]){
//apply binary in the first segment
}
else {
//apply binary in second segment
}
I am not an expert on time complexity, just have seen your previous video.
but for your approach time complexity should be
1 O(log2^n)+O(log2^n)
and for my approach, it should be O(log2^n)
P.s I've just started DSA, so correct me if I am wrong.
Edit- I found my mistake.
How can I apply binary search in the first or second segment if I dont know the pivot element(i.e. start of second segment and end of the first segment.)
Exactly you can not apply binary search in an array without knowing 1st and last index of array
// THis is what i did and it was accepted in leetcode 33
int search(vector& nums, int target) {
int s=0;
int e=nums.size()-1;
int mid=s+(e-s)/2;
while(s=nums[0]){
if(nums[mid]>target)
e=mid-1;
else if(nums[mid]>=nums[0])
s=mid+1;
else
e=mid-1;
}
else{
if(nums[mid]=nums[0])
s=mid+1;
else
e=mid-1;
}
mid=s+(e-s)/2;
}
return -1;
}
@@adarshtiwari2727 brother could you please explain me the Algo ??i can't solve it in leetcode
can u tell me why comparision takes place in 15;40 _ as s=4 and end =4 while statement doesnt satisfy here
Present sir.... Your student josh is always high for the exciting class of DSA#lovebabbar
ye jo first question hai pivot element wala usme hum arr[0] se na compare keke balki arr[end] se kare to jada best hoga kyuki hume nhi pta hota ki sorted array kitni baar rotate kia gya hai kya pata vo rotate hoke sirf sorted hi hogya ho jaise ki {11,12,13,14,15} ye array rotate hoke yhi ban gya to arr[0] se hamara ans galat ayega but arr[end] se hamesha shi ayega ....
//finding the target in sorted rotated array using binary search
//ex-> A = {7,8,9,10,1}
// key = 9
//output -> element found at index 2
//code written by harsh shukla
#include
using namespace std;
int PivotInRotSortArr(int arr[] , int size){
int s = 0 , e = size - 1;
while(s arr[mid+1]){
return mid+1;
}
else if(arr[s]
very helpful, thanks!!
Bhaiya aap kamaal ho mazaa hi ajata hai ye quality Maine abhi tak kisi course main nahin dekhi
Thank you so much bhaiya for bringing such a great, full fledged and premium content in free of cost for all of us ❤🙏🙏🙏.....
We are putting our effort 👌 💪 🙂 👏 🙌
Search in rotated sorted array brute force solution:-
int search(vector& arr, int n, int k)
{
for(int i =0; i
what did i learn from this lecture
1.how to find pivot element in rotated and sorted array
2. how to find an element in rotated and sorted array
3. how to find the square root of an element
4. how to find the precesion of the square root
bhaiya aap smjate hi aaisa ho ki ek baar m smjh aa jaata hai. doosri baar sunna hi nhi padta
This series is very helpful; thanks a lot ❤️
Easier way to implement precision using brute force
double squareroot(int element, int integerpart, int precision){
double ans=integerpart;
double factor=1;
for (int i=1; i
Note - For precision part we can make a function and convert the precision int into floating point num.... like 3 gets converted to 0.001
float num = 37;
float ans = findSqrt(num);
while (true) {
if ((ans + 0.01) * (ans + 0.01) < num) {
ans += 0.01;
} else {
break;
}
}
cout
Nested for loops bro... 😐😐😐
East or west, bhaiya is the best!
Ok didi
you are the best teacher for DSA babbar bhaiya ,
thank to that friend who recommended your channel for DSA
Leaving this comment so that after an year if someone liked this cmmnt i'll be appreciating myself for my hard work. nd surely at that time i'll work in a good MNC.
love from ghaziabad bhaiya:)
what's your update bro
@@Codeycodee well right now I'm pursuing MCA from BHU and getting placed in my 3rd sem🫂
@@Codeycodee what about you brother
@@tusharsingh1915 update brother?
got placed?
Socha nhi tha kabhi RUclips se itna acha content milega. Thanks bhaiya
t's my humble request please maintain this consistency till end. We all are with you bhaiya. Sab ek sath placed honge👍and thankyou
can u tell me why comparision takes place in 15;40 _ as s=4 and end =4 while statement doesnt satisfy here
I am so happy that i solved the square root of n question by myself after understanding the first 2 questions. Thank you so much for this useful lecture
UPDATE GUYZZZZZ...........................Also correct me if i am wrong............the solution for sorted and rotated array can't solved every testcase in the leetcode platform it can solve 133/195 cases.............where array is [ 1 ] ...........target = 1 , output goes -1 but answer expected is 0.......we have to come up with an solution for this edge case....
good
good
This solution pases all the test cases
int lowerPivot(vector& arr, int size){
int s = 0;
int e = size -1;
int mid = s + (e - s)/2;
while(s < e){
if(arr[mid] >= arr[0]){
s = mid + 1;
}
else{
e = mid;
}
mid = s + (e - s)/2;
}
return s;
}
int binarySearch(vector& arr, int s , int e, int key){
int start = s;
int end = e;
int mid = start + (end - start)/2;
while(start
My friend tell me about this daa lecture series and now I learning this series for placement this time my second year is about to completed and really thank you bhaiya ❤️❤️❤️❤️
लाजबाब जबरजस्त जिंदाबाद🙏🙏🙏
Search sorted array mein ham log direct arr[0] se compare nhi kr skte??
If k>arr[0] lies in first prt
Else lies in 2nd part
AMAZING! I was feeling really low today and I really wanted to give up, but I finished it in the end! Super glad :) Thanks bhaiya!
This course is best course for improving the problem solving in DSA
Solution for Search in Sorted Array by splitting in two parts:
Approach:
1. Get Pivot
2. If key == arr[pivot] it is the answer
3. if(key>=arr[0]) it lies in first half therefore, s=0, e = pivot-1
4. else, it lies in second half therefore s= mid, e = size-1
5. Now perform BS based on the selected values of e and s.
Complexity = O(logn)
Code:
int getPivot(vector& arr,int n){
int s = 0;
int e = n-1;
int mid = s + (e-s)/2;
while(s=arr[0]){
s= mid+1;
}else{
e = mid;
}
mid = s+(e-s)/2;
}
return s;
}
int findPosition(vector& arr, int n, int k)
{
int pivot = getPivot(arr,n);
if(arr[pivot]==k){
return pivot;
}
int s,e;
//splitting array based on pivot element
if(k>=arr[0]){
e = pivot-1;
s = 0;
}
else{
e = n-1;
s = pivot;
}
int mid = s + (e-s)/2;
while(sk){
e = mid-1; //move left
}else{
s = mid+1;
}
mid = s+(e-s)/2;
}
return -1;
}
can u tell me why comparision takes place in 15;40 _ as s=4 and end =4 while statement doesnt satisfy here
@@arnobbaiga309 sir ne ek step aur lga de galti sai
actually it dont take olace
@@rahulgopalka2403 right!!
world best free course of DSA thank you Bhai Costly content ko Free me dene ke liye❤❤
Sorry sir , but the question in last video (Find Pivot in an array) was actually a point where left sum = right sum , but in video you are explaining something else . Please clarify this sir .
bro, at that point he means smallest in array.
And in leet code question 33, there is definition of pivot where leftSum = rightSum.
Hope you understand , that it is only a word that is vary from concept to concept
@@anuragsrivastava1995 thank you for trying but you just made it worse for me 😂😂🙏🏽
@@krishnaprabeesh2415 😂😂
> The Pivot index** is the index where the sum of all the numbers **strictly** to the left of the index is equal to the sum of all the numbers **strictly** to the index's right.
**Pivot element** is the only element in input array ( Which is already a rotated sorted array) which is smaller than it's previous element. A pivot element divided a sorted rotated array into two monotonically increasing array.
>
@@vaibhavagrawal431 take one example like 3 4 1 2
Pivot element -1
Sum of left of pivot element -7
Sum of right of pivot element-2
Which is not equal
One hour and I am going to say that you are a great teacher
Quality of the content is great, please continue the work.
Much appreciated!
can u tell me why comparision takes place in 15;40 _ as s=4 and end =4 while statement doesnt satisfy here
@@arnobbaiga309 bro comparision jo h vo phele hua like jab loop khtm nhi hua h and then jab ekk iteration puri hui uske baad s = 4 , e = 4 hua then loop end hogya
bhaiya wo pivot wale question ka kuch or Matlab dia hua tha leet code pe...
find pivot index:-
it is a index where sum of all numbers strictly to the left side of the index is equal to the sum of all the no.s strictly to the index's right.Return the leftmost pivot index.
Thank u bhaiya for giving such a great content 🥰🥰
Not going to quit ...definitely i will complete this whole series properly babbar bhaiya
so on which video u r on?
You are amazing bhai ❤❤. Just one Question can we find square root of float numbers too using binary search?
Bhai aap fire ho... aapne ye course na krwaya hota toh DSA will alaways be a scary thing for most of us. Keep growing brother🔥🔥
MINIMUM ELEMENT IN AN SORTED AND ROTATED ARRAY-
int findMin(int arr[], int n){
//complete the function here
if(arr[0]
can u tell me why comparision takes place in 15;40 _ as s=4 and end =4 while statement doesnt satisfy here
Just completed the video explanation with the graph of pivot was soo good.
Akri thak data raha 🎉
Hat's off to the dedication, every concept is crystal clear, commenting for better reach!!!
can u tell me why comparision takes place in 15;40 _ as s=4 and end =4 while statement doesnt satisfy here
thank you bhaiya..bhot mzza aa rha hai...I observed you are working late night till 5 in the morning😂😂.
bhot hard...bhot hard....bs josh thanda na pdne dena
Excellent stuff and loving this DSA series
Sir ek logic ye bhi laga sakte he na ki...
Apan ne mountain element nikala tha to ager apan last mountain element ka return thoda change ker de to bhi answer aa sakta he na...
Jaise ki...
.......
return array[start+1];
.......
Isse ye ho ki jo top point hoga uska next element mil jaega Jo ki pivot point hoga...
Sir the code for pivot element is not working for some edge cases such as if the sorted array is rotated by zero or rotated by n whr n being the no of elements in the array
is that true or i m doing somewhere wrong.
Bhai really learning a lot from you... Really like your videoes. Now I feel like I am being helped by my elder brother. Thank you so much bhaiya... Just one thing more than 1 hr video ko miss kr rha hu... Thank you so much bhaiya for helping.
bhaiya when we google search and on Leetcode also ..it defines pivot of an array as an index where the sum of all the numbers strictly to the left of the index is equal to the sum of all the numbers strictly to the index's right. can i get some more clarity on pivot of an array .. I'm little confused.
broh, apka confusion solve hua if yes then mujhe v btayen plz
Bhaiyaaa ekdam mazaaa aa rha h DSA padh ke...
Bare Bhaiya apko koti-koti naaman 😇🙏
Love you bro please be constant till the end keep sharing your knowledge May god bless you
Love bhai how to write the code if the question is twisted
maza aagay bhaayya ji . By watching you it keeps increasing my interest in dsa❤❤
@CodeHelp - by Babbar! Bhaiya, you haven't mentioned the solution of " Q-724>> Find the Pivot Element" yet in leetcode?
please, plz make our concept clear regarding that problem.
bhai pivot element hota kya h , plzz explain !!!!
@@summitrawat1093 pivot = minimum element in rotated sorted array
All are going good...The way you present the lecture is excellent. Thank you so much for this DSA course
Rotated Sorted array using the second approach.
int search(int* arr, int n, int k) {
// Write your code here.
int s = 0 , e = n - 1 , mid;
while( s k) e = mid -1;
else if(k > arr[0] && arr[mid] < k) s = mid + 1;
else if(k > arr[0] && arr[mid] > k) e = mid -1;
else return mid;
}
return -1;
}
Code sahi run nahi kar raha bhai!!...
bhai aapke code ki second and third condition wrong he.....
can u tell me why comparision takes place in 15;40 _ as s=4 and end =4 while statement doesnt satisfy here
Over powered -------> Babbar Bhaiya
is se best binary search nhi padha !! Hats off bhaiya ! :) YO!
What is the 2nd and 3rd approach for the Searching element in the sorted rotated array?
He talks about it at 27:44 in the video.
Can anyone please share their approaches?
Approch 2:
int start = 0, end = n - 1;
int mid;
while (start
iss videos mein kuch samajh nhi aa rha hai sir
Search an Element in a Sorted & Rotated array using Binary Search
beat 100 percent without see and discuss answer , now feelling motivated
// search in a sorted rotated array
#include
using namespace std;
int search(vector& nums, int target) {
int s=0;
int e=nums.size()-1;
while(s=nums[0]){
//left side
if(target>=nums[s] && targetnums[mid] && target
Great work ✅👍🏻👍🏻
anuj bhiya ka chap diya kya?
Approach for Pivot Index:
int numsLeft = 0;
int numsRight = accumulate(nums.begin(), nums.end(), 0);
for(int i = 0; i < nums.size(); i++)
{
numsRight -= nums[i];
if(numsRight == numsLeft)
{
return i;
}
numsLeft += nums[i];
}
return -1;
but complexity will be O(n) right?
//Search in a Rotated and Sorted Array
#include
using namespace std;
int search(int a[], int n, int key)
{
int beg=0, end=n-1, mid;
while(beg=a[0])
{
if(keykey)
end=mid-1;
else
beg=mid+1;
}
else if(a[mid]=a[0])
end=mid-1;
else if(a[mid]>key)
end=mid-1;
else
beg=mid+1;
}
}
return -1;
}
int main()
{
int a[]={7,9,10,1,2,3};
int n=sizeof(a)/sizeof(a[0]);
int key=2;
cout
Mast Samjhaya ha Bhaiyya Aapne. Maza aa gaya.
On to the Next Video.
14 Videos Completed. 135 more to go.
I am strongly following you bhaiya.... Thanks, bhaiya for your efforts. This is my consistent 14th lecture.
Samajh toh aa raha hai but I think I need to practice these questions few times in a single week !!! Thank you
bhaiya isse bhadiya content mujhe kahi nhi mila.I really your appreciate your efforts.Keep it up Bhaiya ji
East to West Love Babbar Bhaiya is the best ❤️🙇
We can also add a case like if element is not rotated but sorted then we return it's first element (a leetcode test case) so we can add an if condition like if(arr[0]
Yess but we can find only pivot using this logic , Not a key value k
if only he's a professor in college, then that college would be happiest place on earth --(big fan bhai🖤🖤)
Commenting for reach bhaiya, mai abhi 10th mei but I am preparing for INOI, so cp mei c++ aata hai and aapka hi course dekhunga promise. Abhi mai sabmei commenting for reach krta rahunga
Love you 3000 babbar bhai ❤️
love form Pakistan Bro,
your videos is really helpful for me and my class fellow as I am a university student but your videos means alot to me and my other class fellows.
Thank you soo much for this helpfull series
Precision finding was absolutely awesome
You really deserve more views and likes
in question to find sqrt, we can use end as n/2, because after n/2 there is no number which can be a multiple of n
bhaiya pivot element toh vo hota h na jisske left side ke elements ak sum right side ke elements ke sum ke equal ho....but aapne toh pure array me minimum element ko hi pivot bataya h...toh pivot ki koi pele se defination nhi hoti ky?...aur ky pivot element question to question vary krte h?
very smooth way of teaching . Concept has been settled in the mind like if it is present there from the beginning.
Seach element in rotated sorted array has 3 approach
1) discussed in lecture involving pivot
2) comparison with arr[0] and directly binary search
But I am confused with the 3rd approach of which bhaiya was giving hint
Please clarify 😅
One doubt in sqre rot question - Can we not find precision again with binary search.
For example- if we want precision of 2, then s=0.01 and e= 0.99 and then we can calculate via binary search.
bro can u help me with my doubt,
@@computerscience1099 Yes tell me
good love this video.....become millionare soon bro