BS-2. Implement Lower Bound and Upper Bound | Search Insert Position | Floor and Ceil
ฝัง
- เผยแพร่เมื่อ 4 ส.ค. 2024
- Lower Bound: bit.ly/43967G5
Upper Bound: bit.ly/3IoKGce
Search Insert Position: bit.ly/3ocI0HW
Floor and Ceil: www.codingninjas.com/codestud...
Notes/C++/Java/Python codes:
Implement Lower Bound: takeuforward.org/arrays/imple...
Implement Upper Bound: takeuforward.org/arrays/imple...
Search Insert Position: takeuforward.org/arrays/searc...
Floor/Ceil in Sorted Array: takeuforward.org/arrays/floor...
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 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
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 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]
Really great series. Made in such a way easy to understand in no time. Great work 👏
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
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 .
I am actually revising my concept and this Binary search series has been helpful.
Thanks Striver
Understood! Super amazing explanation as always, thank you very very much for your effort!!
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 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!
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++
UNDERSTOOOOOOOD!!!!, was able to solve both problems as soon as you taught the lowerbound approach.
understood everything. You are doing great work, keep it up!
this man is a gem!
your understanding about Dsa is excellent
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?
This content is gold.
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
Was able to do every single question after lower bound by my self thanks ❤❤. Literally built my thinking ability.
kya padhate hooo bhai tum mera dil happy happy hoo gaya jaise aapne explain kiya hain maza aa gaya
Understood clearly
Understood everything.... Feels like you will taking me forward from my Village to google or Microsoft or Amazon fore sure ❤❤
Understood,Thank you striver for this amazing video.
yet another amazing explanation by striver
Much love to your work Raj bhai (Striver)❤🙏
Understood sir! Golden video!
You explained it very well .... thank you so much sir for your efforts .❤
Wowww .... finally 🎉🎉❤❤thank you striver 🤗🤗
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
love for the knowledge you have respect man!!🤓
Understood, Great explanation Brother, Thank you
Understood very well!!!
Very beautifully explained Raj. And that ans technique was too good. Really helpful. Good work bhai.
Understood...explanation was really awesome ❤😊
Really great series I really appreciate lot thanks bro.
Understood Sir. Loved it. Thank you
crystal clear understood thank you so much
you have beautifully explained this topic
understood
Thank You @striver for making things so easy...❤❤
Understood very well.👌👌
Understood clearly!
Understood, Thank you sir!
TQSM understood Very Elegant way of code
Amazing explanation . Thank you sir ❤❤
Thank You... I understood it very well :)
Great class. i liked it a lot . Thank 😀u for simple explaination
understood amazing explaination
Thank you bro ❤ loved the lecture
Understood Bhaiya!
Very well explained...
amazing session
clear explanation!
understood !! thank you so much
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 thanks striver for amazing video
awesome lecture... what an explanation 🔥🔥🔥🔥
Really helpful lec
understood everything bhaiya .. thankyou
Understood Very Well
understood very well
Awesome 👍
Thank you Striver, My Intuition is actually improving. Its not about solving the problems, its about understanding the diverse approach.
Understood ❤
Understood Sir 🌟
Understood, thank you.
great explanation understood
great teaching
Understood Sir 🙌
UNDERSTOOD❤
Understood well...!!
understood, thanks!
Nicely explained
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 :)
Understood!❤
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 bhaiya thanks a lot man🙂
striver u r a genius ❣
NICE SUPER EXCELLENT MOTIVATED
UNDERSTOOD!
ultimate! 👏
Understood : ) thanks
understood binary search thank you sir
understood sir ...thanks a lot
understood!
Nice explanation
Understood 😊
Understood 👍👍
Understood! 🎉
Understooood!
Thank you Sir ❤
Thank you 😊😊
Here it is finally
maja aa gya striver bhaiya
Understood ❤
extran ordinary explanation
Thank You
understood ❤
Understood✅🔥🔥
understood!!!
understood🤟
Understood 😊😊
awesome🤩🤩🤩😍😍😍😍
understood, no chance of any doubt