Sir, how lower and upper bound different just by removing an equal to sign. Why lower bound is not the largest value just smaller or equal to the given value?
@@RachitAgnihotriBEE bro why your name is rachit not prachi even if just adding P and removing T from your name. hope so you got the answer there is a difference of equal to sign thats why there name is different as lower and upper bound.
@@rjedits6717 mujhe Gyan Dene se accha jakar lower bound or upper bound ka diff dekhle , kabhi set jesa kuchh padha hoga 10th or 12th me to smjh aa jaega ,
I was fearing from binary search but once Understood in depth ,I was able to do all question in this lecture my self . Thank you so much for this wonderful explanation .Just keep doing it .
Floor and Ceil without using "ans" variable - > For floor just do a normal binary search and return end > For ceil just do a normal binary search and return start
yes , because for floor , the end/high pointer needs to go to lower search space (mid-1) and for ceil the low/start pointer needs to go to higher search space (mid + 1)
#Free Education For All.. # Bhishma Pitamah of DSA...You could have earned in lacs by putting it as paid couses on udamey or any other elaerning portals, but you decided to make it free...it requires a greate sacrifice and a feeling of giving back to community, there might be very few peope in world who does this...."विद्या का दान ही सर्वोत्तम दान होता है" Hats Off to you man, Salute from 10+ yrs exp guy from BLR, India.
0:00 Lower Bound Explanation using examples 10:53 Lower Bound Implementation 13:35 Lower Bound Code (in C++) 13:55 lower_bound() C++ STL method 15:33 Time Complexity Analysis of Lower Bound 15:46 Upper Bound Explanation using examples 17:23 Upper Bound Implementation 18:56 Upper Bound Code (in C++) 19:13 Time Complexity of Upper Bound 19:20 upper_bound() C++ STL method 19:47 Search Insert Position 22:53 Floor and Ceil in Sorted Array 28:44 How is Binary Search making sure that we get the smallest index? 31:40 Outro
@@recordings8956 class Solution: def findFloor(self,A,N,X): l=0 h =N-1 ans=N if X < A[0]: return -1 while l=X: ans = mid h = mid-1 else: l =mid+1 return ans I corrected my code but its still not working
i am on the verge of completing this a2z sheet ,hopefully i will do it by the end of june by myself on my own pace since the tougher side of the sheet is already been done by me... u r gem of a person Raj bhya..♥
@@sauravchandra10 Na bro I wanted to ask how you practice the question cause as days passed by things start to pile up 🥲 , nd then i started to forgot ....how ou beat this?
Completely understood your solution and intuition. One thing I especially like about your channel is the intuition building and clean intuitive code. For eg. in the last part when you told about either low/high to be our answer, it is very intuitive to make ans variable instead of returning either one. Really appreciate the efforts and free content.
Sir your lectures are very very helpful to us.. This type of content to provide free is very hard.. We are really thank full to you.. I was watching your lecture from 10 days.. Then today I just realize to do just thankfull to you..😊😊blessings++
Search insert Position : My code : int searchInsert(vector& arr, int m) { // Write your code here. int n=arr.size(); int left=0; int right=n-1; if(m>arr[n-1]){ return n; } if(m
In java there is no direct method to find lower bound or upper bound but indirectly you can find with the help of Arrays.binarySearch(arr,target) method public class Solution { public static int lowerBound(int []arr, int n, int x) { // Write your code here int ans = Arrays.binarySearch(arr, x); // built in method for binary search it will return the smallest index where target is present i.e lower bound else it will return a negative value if(ans
Yes, Initially on pen & paper. I tried to solve the problem by myself only. There I was getting help from low & high pointers only but there were some of the end cases which I was not able to pass.
Bro, You are awesome. I will try to make video from my side as well. The content will be inspired from you rather than copied. As this makes mine coding habit better. Thanks
@21:12 When the array is [1, 2, 4, 7] and your target is 2, you need to return the index of 2 as it is present in the array. Please revisit the question @19:57. The Search Insert Position does not reduce to Lower Bound problem.
Upper bound - first occurance of smallest number in array such that number > target Lower bound - first occurance of smallest number in array such that number >= target - same as ceil Floor - first occurance of largest number in array such that number
Amazing and just a cake walk now.Bhaiya I'm bit confused and figuring out the right way we should learn DSA , I mean which roadmap must be followed while learning DSA i.e String --> Array--> .... something like this.If anyone know please do let me know. And huge love and appreciation for your dedication and hardwork❤.Thankyou soo much bhaiya
Try to cover arrays first. After that go for strings. Then you can go for linked lists, stacks and queues and then step onto advance data structures like graphs, trees and tries. After completing all these, focus on design and analysis of algorithms like DP, Greedy and try optimizing the all the data structures that you've learnt.
my approach is like i will be searching for the element -1)if found return the index 2) if not return the next lower bound where it stopped But 1 testcase in optimal code test is failed. I just want to know where i am missing?😕 Even the above code giving the same. int searchInsert(vector& arr, int m) { // Write your code here. int low = 0; int high = arr.size()-1;
while(high>=low){ int mid = low+(high-low)/2; if(arr[mid]==m){ return mid; } else if (arr[mid]>m){ high = mid-1; } else{ low = mid+1; } } return low; }
Most Optimized solution for Floor and Ceil. 1binary search call instead of 2 pair getFloorAndCeil(vector &a, int n, int x) { int start=0; int end = n-1; int floor =-1; int ceil =-1; while(start
int upperBound( vector arr, int n, int x ) { int low = 0 ; int high = n-1; int ans = n ; while(low x){ ans = mid; high = mid - 1; } else{ low = mid + 1; } } return ans; }
Please comment understood and give us a like if you got everything :)
Sir, how lower and upper bound different just by removing an equal to sign. Why lower bound is not the largest value just smaller or equal to the given value?
understood
@@RachitAgnihotriBEE bro why your name is rachit not prachi even if just adding P and removing T from your name. hope so you got the answer there is a difference of equal to sign thats why there name is different as lower and upper bound.
@@rjedits6717 mujhe Gyan Dene se accha jakar lower bound or upper bound ka diff dekhle , kabhi set jesa kuchh padha hoga 10th or 12th me to smjh aa jaega ,
Understood
27:00 a litlle error please correct if(a[mid]
Thanks had that confusion
Cool thanks Saket
thanks yar ❤❤ had a same doubt
Can u explain
@@sneha_109 yes I can
I was fearing from binary search but once Understood in depth ,I was able to do all question in this lecture my self .
Thank you so much for this wonderful explanation .Just keep doing it .
Floor and Ceil without using "ans" variable -
> For floor just do a normal binary search and return end
> For ceil just do a normal binary search and return start
Thanks pal!
doesn't work
correct!
pair getFloorAndCeil(vector &a, int n, int x) {
int low = 0, high = n-1;
pair p;
while(low x){
high = mid - 1;
}else{
low = mid + 1;
}
}
p.first = high >= 0 ? a[high] : -1;
p.second = low
yes , because for floor , the end/high pointer needs to go to lower search space (mid-1) and for ceil the low/start pointer needs to go to higher search space (mid + 1)
thanks daddyyy
#Free Education For All.. # Bhishma Pitamah of DSA...You could have earned in lacs by putting it as paid couses on udamey or any other elaerning portals, but you decided to make it free...it requires a greate sacrifice and a feeling of giving back to community, there might be very few peope in world who does this...."विद्या का दान ही सर्वोत्तम दान होता है" Hats Off to you man, Salute from 10+ yrs exp guy from BLR, India.
0:00 Lower Bound Explanation using examples
10:53 Lower Bound Implementation
13:35 Lower Bound Code (in C++)
13:55 lower_bound() C++ STL method
15:33 Time Complexity Analysis of Lower Bound
15:46 Upper Bound Explanation using examples
17:23 Upper Bound Implementation
18:56 Upper Bound Code (in C++)
19:13 Time Complexity of Upper Bound
19:20 upper_bound() C++ STL method
19:47 Search Insert Position
22:53 Floor and Ceil in Sorted Array
28:44 How is Binary Search making sure that we get the smallest index?
31:40 Outro
I am actually revising my concept and this Binary search series has been helpful.
Thanks Striver
Really great series. Made in such a way easy to understand in no time. Great work 👏
i feel the lower bound explanation and the provided GFG questions don't match with each other, question might be modified after some time
Yes, it’s different 🫡
just add this condition in beginning:
if(x < v[0]) return -1;
What is v here@@recordings8956
@@recordings8956 class Solution:
def findFloor(self,A,N,X):
l=0
h =N-1
ans=N
if X < A[0]:
return -1
while l=X:
ans = mid
h = mid-1
else:
l =mid+1
return ans
I corrected my code but its still not working
@@aishwarybhat5673
if(a[mid]
i am on the verge of completing this a2z sheet ,hopefully i will do it by the end of june by myself on my own pace since the tougher side of the sheet is already been done by me... u r gem of a person Raj bhya..♥
which topics do you have covered till now?
I don't usually comment on youtube, but I had to login just to say how incredible was this lesson! Thanks very much for this videos!
Understood everything.... Feels like you will taking me forward from my Village to google or Microsoft or Amazon fore sure ❤❤
Completed graph and dp series in the previous 20 days, and I am super excited to complete this BS playlist as well.
how did u practice question , what strategy do you use, cause there are so many videos?
@@kshitijtakarkhede7833 I targeted atleast 5 videos daily
@@sauravchandra10 Na bro I wanted to ask how you practice the question cause as days passed by things start to pile up 🥲 , nd then i started to forgot ....how ou beat this?
@@kshitijtakarkhede7833 just do these problems 2 3 times because these problems are most likely to be asked
@@sauravchandra10 thanks bro
Thank you Striver, My Intuition is actually improving. Its not about solving the problems, its about understanding the diverse approach.
Understood ❤
kya padhate hooo bhai tum mera dil happy happy hoo gaya jaise aapne explain kiya hain maza aa gaya
Understood clearly
Completely understood your solution and intuition. One thing I especially like about your channel is the intuition building and clean intuitive code. For eg. in the last part when you told about either low/high to be our answer, it is very intuitive to make ans variable instead of returning either one. Really appreciate the efforts and free content.
Bro can you share code of ceil the floor question
Understood! Super amazing explanation as always, thank you very very much for your effort!!
UNDERSTOOOOOOOD!!!!, was able to solve both problems as soon as you taught the lowerbound approach.
Sir your lectures are very very helpful to us.. This type of content to provide free is very hard.. We are really thank full to you.. I was watching your lecture from 10 days.. Then today I just realize to do just thankfull to you..😊😊blessings++
your understanding about Dsa is excellent
thanks for all raj i can see my improvement in problem solving i can't express my feeling
Was able to do every single question after lower bound by my self thanks ❤❤. Literally built my thinking ability.
Search insert Position :
My code :
int searchInsert(vector& arr, int m)
{
// Write your code here.
int n=arr.size();
int left=0;
int right=n-1;
if(m>arr[n-1]){
return n;
}
if(m
In java there is no direct method to find lower bound or upper bound but indirectly you can find with the help of Arrays.binarySearch(arr,target) method
public class Solution {
public static int lowerBound(int []arr, int n, int x) {
// Write your code here
int ans = Arrays.binarySearch(arr, x); // built in method for binary search it will return the smallest index where target is present i.e lower bound else it will return a negative value
if(ans
No point of using it for interviews
Small Small 9:17 wow, what an enthusiasm for teaching and what a style to deliver I wish I had these skills too love you striver bhaii :)
This content is gold.
this man is a gem!
Very beautifully explained Raj. And that ans technique was too good. Really helpful. Good work bhai.
Yes, Initially on pen & paper. I tried to solve the problem by myself only. There I was getting help from low & high pointers only but there were some of the end cases which I was not able to pass.
understood everything. You are doing great work, keep it up!
for floor we can also do upper_bound index -- 1 to get the index of floor
You explained it very well .... thank you so much sir for your efforts .❤
Bro, You are awesome. I will try to make video from my side as well. The content will be inspired from you rather than copied. As this makes mine coding habit better. Thanks
understood
Thank You @striver for making things so easy...❤❤
yet another amazing explanation by striver
Much love to your work Raj bhai (Striver)❤🙏
Wowww .... finally 🎉🎉❤❤thank you striver 🤗🤗
TQSM understood Very Elegant way of code
you have beautifully explained this topic
@21:12 When the array is [1, 2, 4, 7] and your target is 2, you need to return the index of 2 as it is present in the array. Please revisit the question @19:57. The Search Insert Position does not reduce to Lower Bound problem.
Understood sir! Golden video!
Upper bound - first occurance of smallest number in array such that number > target
Lower bound - first occurance of smallest number in array such that number >= target - same as ceil
Floor - first occurance of largest number in array such that number
Instead of using 'ans' variable
For floor -> return low-1
For ceil -> return high+1
🎉🎉🎉
Amazing and just a cake walk now.Bhaiya I'm bit confused and figuring out the right way we should learn DSA , I mean which roadmap must be followed while learning DSA i.e String --> Array--> .... something like this.If anyone know please do let me know.
And huge love and appreciation for your dedication and hardwork❤.Thankyou soo much bhaiya
Try to cover arrays first. After that go for strings. Then you can go for linked lists, stacks and queues and then step onto advance data structures like graphs, trees and tries.
After completing all these, focus on design and analysis of algorithms like DP, Greedy and try optimizing the all the data structures that you've learnt.
Really helpful lec
Understood,Thank you striver for this amazing video.
awesome lecture... what an explanation 🔥🔥🔥🔥
Here it is finally
(low + high) could overflow, you should low + (high - low) so it doesn't break for large data
Understood Bhaiya!
Very well explained...
Understood...explanation was really awesome ❤😊
crystal clear understood thank you so much
Understood, Great explanation Brother, Thank you
Great class. i liked it a lot . Thank 😀u for simple explaination
understood amazing explaination
striver u r a genius ❣
Understood Sir. Loved it. Thank you
my approach is like i will be searching for the element -1)if found return the index 2) if not return the next lower bound where it stopped
But 1 testcase in optimal code test is failed. I just want to know where i am missing?😕 Even the above code giving the same.
int searchInsert(vector& arr, int m)
{
// Write your code here.
int low = 0;
int high = arr.size()-1;
while(high>=low){
int mid = low+(high-low)/2;
if(arr[mid]==m){
return mid;
}
else if (arr[mid]>m){
high = mid-1;
}
else{
low = mid+1;
}
}
return low;
}
Understood thanks striver for amazing video
Really great series I really appreciate lot thanks bro.
understood everything bhaiya .. thankyou
This also done on 28 Aril 2024 , Best explain bro
Most Optimized solution for Floor and Ceil. 1binary search call instead of 2
pair getFloorAndCeil(vector &a, int n, int x) {
int start=0;
int end = n-1;
int floor =-1;
int ceil =-1;
while(start
UNDERSTOOD❤
Understood clearly!
Understood very well.👌👌
Taught us problems based on lower_bound and upper_bound and bounds problem also, Understood
Understood bhaiya thanks a lot man🙂
Understood very well!!!
Nicely explained
Understood Sir 🌟
understood binary search thank you sir
Amazing explanation . Thank you sir ❤❤
Awesome 👍
love for the knowledge you have respect man!!🤓
int upperBound( vector arr, int n, int x ) {
int low = 0 ;
int high = n-1;
int ans = n ;
while(low x){
ans = mid;
high = mid - 1;
}
else{
low = mid + 1;
}
}
return ans;
}
extran ordinary explanation
great teaching
According to me u are my god..❤️🙏
understood, no chance of any doubt
Really really very much helping aab Mai phod dunga
13:20 (arr[mid] >= target) instead of (arr[mid] >= n)
Understood Very Well
Understood, Thank you sir!
NICE SUPER EXCELLENT MOTIVATED
isn't the if condition for lower bound should be
if(v[mid]
Understood 😊
31:35 understood sir!
amazing session
great explanation understood
clear explanation!
Nice explanation
why your Strivers a to z sheet is not opening. Whenever i'm trying to open it it only shows rounding circle. And only 19 th section is visible
Understood Sir Thankyou Sir🙏🙇♂✨
understood very well
Thank You... I understood it very well :)
Understood, thank you.
Understood! 🎉
Thank you bro ❤ loved the lecture
Understood!