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

ความคิดเห็น • 389

  • @takeUforward
    @takeUforward  ปีที่แล้ว +91

    Please comment understood and give us a like if you got everything :)

    • @RachitAgnihotriBEE
      @RachitAgnihotriBEE ปีที่แล้ว +3

      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?

    • @sudhanshushekhar4222
      @sudhanshushekhar4222 ปีที่แล้ว

      understood

    • @rjedits6717
      @rjedits6717 ปีที่แล้ว

      @@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.

    • @RachitAgnihotriBEE
      @RachitAgnihotriBEE ปีที่แล้ว +1

      @@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 ,

    • @jeet-smokey
      @jeet-smokey 11 หลายเดือนก่อน

      Understood

  • @saketjaiswal9381
    @saketjaiswal9381 ปีที่แล้ว +173

    27:00 a litlle error please correct if(a[mid]

    • @yashrajdeshmukh6759
      @yashrajdeshmukh6759 9 หลายเดือนก่อน +9

      Thanks had that confusion

    • @Hassainsyed
      @Hassainsyed 8 หลายเดือนก่อน +7

      Cool thanks Saket

    • @thefourhourtalk
      @thefourhourtalk 2 หลายเดือนก่อน +2

      thanks yar ❤❤ had a same doubt

    • @sneha_109
      @sneha_109 24 วันที่ผ่านมา

      Can u explain

    • @thefourhourtalk
      @thefourhourtalk 24 วันที่ผ่านมา

      @@sneha_109 yes I can

  • @sagarhiremath4899
    @sagarhiremath4899 หลายเดือนก่อน +43

    i feel the lower bound explanation and the provided GFG questions don't match with each other, question might be modified after some time

    • @tanoysaha4575
      @tanoysaha4575 29 วันที่ผ่านมา

      Yes, it’s different 🫡

    • @recordings8956
      @recordings8956 26 วันที่ผ่านมา

      just add this condition in beginning:
      if(x < v[0]) return -1;

    • @mr.kaushik8518
      @mr.kaushik8518 20 วันที่ผ่านมา

      What is v here​@@recordings8956

    • @aishwarybhat5673
      @aishwarybhat5673 13 วันที่ผ่านมา

      ​@@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

    • @pratiksingh4700
      @pratiksingh4700 13 วันที่ผ่านมา

      ​@@aishwarybhat5673
      if(a[mid]

  • @mianawais99
    @mianawais99 ปีที่แล้ว +6

    Really great series. Made in such a way easy to understand in no time. Great work 👏

  • @shaurya2608
    @shaurya2608 ปีที่แล้ว +55

    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

    • @nagame859
      @nagame859 ปีที่แล้ว +3

      Thanks pal!

    • @nostalgiccringeallhailchel3881
      @nostalgiccringeallhailchel3881 ปีที่แล้ว +1

      doesn't work

    • @zerr0n7eet
      @zerr0n7eet 6 หลายเดือนก่อน +3

      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

    • @SWATHYBMIS
      @SWATHYBMIS 5 หลายเดือนก่อน +2

      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)

    • @RaghavSingla-er9ub
      @RaghavSingla-er9ub หลายเดือนก่อน

      thanks daddyyy

  • @shashikumar2382
    @shashikumar2382 ปีที่แล้ว +12

    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 .

  • @habeeblaimusa4466
    @habeeblaimusa4466 ปีที่แล้ว +8

    I am actually revising my concept and this Binary search series has been helpful.
    Thanks Striver

  • @cinime
    @cinime ปีที่แล้ว +5

    Understood! Super amazing explanation as always, thank you very very much for your effort!!

  • @anuragsingh8910
    @anuragsingh8910 ปีที่แล้ว +33

    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

  • @thenriquevicentini
    @thenriquevicentini 3 หลายเดือนก่อน +2

    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!

  • @rahulsidhu5945
    @rahulsidhu5945 ปีที่แล้ว +1

    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++

  • @vishious14
    @vishious14 6 หลายเดือนก่อน +2

    UNDERSTOOOOOOOD!!!!, was able to solve both problems as soon as you taught the lowerbound approach.

  • @jyothishreddynagaram6789
    @jyothishreddynagaram6789 3 หลายเดือนก่อน +1

    understood everything. You are doing great work, keep it up!

  • @codiescoderszone1518
    @codiescoderszone1518 ปีที่แล้ว +3

    this man is a gem!

  • @rahulkumarsingh5278
    @rahulkumarsingh5278 8 วันที่ผ่านมา

    your understanding about Dsa is excellent

  • @abhishekverma7604
    @abhishekverma7604 ปีที่แล้ว +8

    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..♥

  • @OscarMartinez-nt6zn
    @OscarMartinez-nt6zn หลายเดือนก่อน +1

    This content is gold.

  • @sauravchandra10
    @sauravchandra10 ปีที่แล้ว +9

    Completed graph and dp series in the previous 20 days, and I am super excited to complete this BS playlist as well.

    • @kshitijtakarkhede7833
      @kshitijtakarkhede7833 ปีที่แล้ว +1

      how did u practice question , what strategy do you use, cause there are so many videos?

    • @sauravchandra10
      @sauravchandra10 ปีที่แล้ว +2

      @@kshitijtakarkhede7833 I targeted atleast 5 videos daily

    • @kshitijtakarkhede7833
      @kshitijtakarkhede7833 ปีที่แล้ว +2

      @@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?

    • @sauravchandra10
      @sauravchandra10 ปีที่แล้ว +3

      @@kshitijtakarkhede7833 just do these problems 2 3 times because these problems are most likely to be asked

    • @kshitijtakarkhede7833
      @kshitijtakarkhede7833 ปีที่แล้ว

      @@sauravchandra10 thanks bro

  • @graviton001
    @graviton001 8 วันที่ผ่านมา

    Was able to do every single question after lower bound by my self thanks ❤❤. Literally built my thinking ability.

  • @AyushKumar-kx3oz
    @AyushKumar-kx3oz ปีที่แล้ว +1

    kya padhate hooo bhai tum mera dil happy happy hoo gaya jaise aapne explain kiya hain maza aa gaya
    Understood clearly

  • @DTALKS01
    @DTALKS01 หลายเดือนก่อน +2

    Understood everything.... Feels like you will taking me forward from my Village to google or Microsoft or Amazon fore sure ❤❤

  • @hareshnayak7302
    @hareshnayak7302 4 หลายเดือนก่อน

    Understood,Thank you striver for this amazing video.

  • @wog4299
    @wog4299 9 หลายเดือนก่อน

    yet another amazing explanation by striver

  • @smitj5404
    @smitj5404 7 หลายเดือนก่อน

    Much love to your work Raj bhai (Striver)❤🙏

  • @harshitjaiswal9439
    @harshitjaiswal9439 7 หลายเดือนก่อน

    Understood sir! Golden video!

  • @kiranmoura2974
    @kiranmoura2974 ปีที่แล้ว +1

    You explained it very well .... thank you so much sir for your efforts .❤

  • @amitkoushik5504
    @amitkoushik5504 ปีที่แล้ว +1

    Wowww .... finally 🎉🎉❤❤thank you striver 🤗🤗

  • @nitesh1543
    @nitesh1543 11 หลายเดือนก่อน +14

    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

    • @chethanprabhu4475
      @chethanprabhu4475 หลายเดือนก่อน

      No point of using it for interviews

  • @rahulkarki6857
    @rahulkarki6857 ปีที่แล้ว

    love for the knowledge you have respect man!!🤓

  • @shrirambalaji2915
    @shrirambalaji2915 ปีที่แล้ว

    Understood, Great explanation Brother, Thank you

  • @sahibahmad3880
    @sahibahmad3880 ปีที่แล้ว

    Understood very well!!!

  • @utsavseth6573
    @utsavseth6573 ปีที่แล้ว +1

    Very beautifully explained Raj. And that ans technique was too good. Really helpful. Good work bhai.

  • @falaknaaz789
    @falaknaaz789 ปีที่แล้ว

    Understood...explanation was really awesome ❤😊

  • @Manasidas99
    @Manasidas99 10 หลายเดือนก่อน

    Really great series I really appreciate lot thanks bro.

  • @kaushiksen2190
    @kaushiksen2190 10 หลายเดือนก่อน

    Understood Sir. Loved it. Thank you

  • @mohammadasif5798
    @mohammadasif5798 21 วันที่ผ่านมา

    crystal clear understood thank you so much

  • @user-ww7kv3un2h
    @user-ww7kv3un2h 2 หลายเดือนก่อน

    you have beautifully explained this topic

  • @user-ti3bd8mp1w
    @user-ti3bd8mp1w ปีที่แล้ว +1

    understood
    Thank You @striver for making things so easy...❤❤

  • @abhisatya23
    @abhisatya23 10 หลายเดือนก่อน

    Understood very well.👌👌

  • @rahulreddy3588
    @rahulreddy3588 9 หลายเดือนก่อน

    Understood clearly!

  • @VarunKaushal-zx9zq
    @VarunKaushal-zx9zq 11 หลายเดือนก่อน

    Understood, Thank you sir!

  • @them.pranay7196
    @them.pranay7196 9 หลายเดือนก่อน

    TQSM understood Very Elegant way of code

  • @sayan_31
    @sayan_31 ปีที่แล้ว

    Amazing explanation . Thank you sir ❤❤

  • @manavsingh5919
    @manavsingh5919 11 หลายเดือนก่อน

    Thank You... I understood it very well :)

  • @shivarajbandaru2216
    @shivarajbandaru2216 9 หลายเดือนก่อน

    Great class. i liked it a lot . Thank 😀u for simple explaination

  • @ayushsharma-bi7zj
    @ayushsharma-bi7zj 29 วันที่ผ่านมา

    understood amazing explaination

  • @jasmeetsingh5174
    @jasmeetsingh5174 ปีที่แล้ว

    Thank you bro ❤ loved the lecture

  • @infernogamer52
    @infernogamer52 ปีที่แล้ว

    Understood Bhaiya!
    Very well explained...

  • @raunakkumarmishra1449
    @raunakkumarmishra1449 ปีที่แล้ว

    amazing session

  • @nehathakur40
    @nehathakur40 ปีที่แล้ว

    clear explanation!

  • @khushiii8672
    @khushiii8672 ปีที่แล้ว

    understood !! thank you so much

  • @HarshKumar-ip5nr
    @HarshKumar-ip5nr ปีที่แล้ว +3

    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.

    • @himanshukaushik9223
      @himanshukaushik9223 ปีที่แล้ว +1

      Bro can you share code of ceil the floor question

  • @YASWANTHSIDDANATHAM-mi8qk
    @YASWANTHSIDDANATHAM-mi8qk 2 หลายเดือนก่อน

    Understood thanks striver for amazing video

  • @AkshitGupta-mp6he
    @AkshitGupta-mp6he 2 หลายเดือนก่อน

    awesome lecture... what an explanation 🔥🔥🔥🔥

  • @user-qi9wt1em7d
    @user-qi9wt1em7d 3 หลายเดือนก่อน +1

    Really helpful lec

  • @riyabankawat4998
    @riyabankawat4998 หลายเดือนก่อน

    understood everything bhaiya .. thankyou

  • @AnmolGupta-oj4lm
    @AnmolGupta-oj4lm ปีที่แล้ว

    Understood Very Well

  • @ramanjaneyuluv479
    @ramanjaneyuluv479 ปีที่แล้ว

    understood very well

  • @rohitprasad2147
    @rohitprasad2147 ปีที่แล้ว +1

    Awesome 👍

  • @senseiAree
    @senseiAree 10 หลายเดือนก่อน +13

    Thank you Striver, My Intuition is actually improving. Its not about solving the problems, its about understanding the diverse approach.
    Understood ❤

  • @simarjeetkaur6781
    @simarjeetkaur6781 ปีที่แล้ว +1

    Understood Sir 🌟

  • @NazeerBashaShaik
    @NazeerBashaShaik 3 หลายเดือนก่อน

    Understood, thank you.

  • @nikhilnallagoni7379
    @nikhilnallagoni7379 ปีที่แล้ว

    great explanation understood

  • @khanzarin9960
    @khanzarin9960 10 หลายเดือนก่อน

    great teaching

  • @aakashsharma780
    @aakashsharma780 ปีที่แล้ว

    Understood Sir 🙌

  • @per.seus._
    @per.seus._ 11 หลายเดือนก่อน +1

    UNDERSTOOD❤

  • @ashutoshkr99
    @ashutoshkr99 ปีที่แล้ว

    Understood well...!!

  • @DR-mq1le
    @DR-mq1le ปีที่แล้ว

    understood, thanks!

  • @peanutcoder9361
    @peanutcoder9361 3 วันที่ผ่านมา

    Nicely explained

  • @areebahmed3561
    @areebahmed3561 23 วันที่ผ่านมา +1

    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 :)

  • @surbhirathore._
    @surbhirathore._ หลายเดือนก่อน

    Understood!❤

  • @harshverm776
    @harshverm776 7 หลายเดือนก่อน

    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.

  • @makingthamilan1592
    @makingthamilan1592 3 หลายเดือนก่อน

    Understood bhaiya thanks a lot man🙂

  • @MAHESHAITBECS
    @MAHESHAITBECS 13 วันที่ผ่านมา

    striver u r a genius ❣

  • @ganeshjaggineni4097
    @ganeshjaggineni4097 2 หลายเดือนก่อน

    NICE SUPER EXCELLENT MOTIVATED

  • @harsh6810
    @harsh6810 ปีที่แล้ว

    UNDERSTOOD!

  • @sukhjattana5887
    @sukhjattana5887 ปีที่แล้ว

    ultimate! 👏

  • @KCOYASH
    @KCOYASH ปีที่แล้ว

    Understood : ) thanks

  • @SureshKrish-uf6ht
    @SureshKrish-uf6ht 12 วันที่ผ่านมา

    understood binary search thank you sir

  • @RaviKumar-sn6tu
    @RaviKumar-sn6tu 4 หลายเดือนก่อน

    understood sir ...thanks a lot

  • @kushagramishra5638
    @kushagramishra5638 ปีที่แล้ว +1

    understood!

  • @k.satish3663
    @k.satish3663 ปีที่แล้ว

    Nice explanation

  • @k.s5964
    @k.s5964 หลายเดือนก่อน +1

    Understood 😊

  • @kiranmoura2974
    @kiranmoura2974 ปีที่แล้ว

    Understood 👍👍

  • @praveenkanwar953
    @praveenkanwar953 18 ชั่วโมงที่ผ่านมา

    Understood! 🎉

  • @mohdrihanali2164
    @mohdrihanali2164 10 หลายเดือนก่อน

    Understooood!

  • @alkasingh2124
    @alkasingh2124 ปีที่แล้ว

    Thank you Sir ❤

  • @Mythri333
    @Mythri333 9 หลายเดือนก่อน

    Thank you 😊😊

  • @abdullahanis5761
    @abdullahanis5761 ปีที่แล้ว

    Here it is finally

  • @CodeNinjaByte
    @CodeNinjaByte ปีที่แล้ว

    maja aa gya striver bhaiya

  • @mohitsingh13
    @mohitsingh13 5 วันที่ผ่านมา

    Understood ❤

  • @AbdurRahman-sp6sm
    @AbdurRahman-sp6sm 10 หลายเดือนก่อน

    extran ordinary explanation

  • @mdsajidanwar6416
    @mdsajidanwar6416 10 หลายเดือนก่อน

    Thank You

  • @khalasianiket816
    @khalasianiket816 หลายเดือนก่อน

    understood ❤

  • @YourCodeVerse
    @YourCodeVerse 7 หลายเดือนก่อน

    Understood✅🔥🔥

  • @adityarajsrivastava3291
    @adityarajsrivastava3291 หลายเดือนก่อน

    understood!!!

  • @hallupandet228
    @hallupandet228 ปีที่แล้ว

    understood🤟

  • @GarimaShukla-jq8sf
    @GarimaShukla-jq8sf 11 วันที่ผ่านมา

    Understood 😊😊

  • @ArpanChakraborty-do6yz
    @ArpanChakraborty-do6yz 6 หลายเดือนก่อน

    awesome🤩🤩🤩😍😍😍😍

  • @user-ke7fs7ds6h
    @user-ke7fs7ds6h 7 หลายเดือนก่อน

    understood, no chance of any doubt