Lecture14: Binary Search Interview Questions [Google, Amazon, Microsoft] || ProblemSet - 2

แชร์
ฝัง
  • เผยแพร่เมื่อ 20 ก.ย. 2024

ความคิดเห็น • 1.1K

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

    Do make sure to visit Relevel: relvl.co/tv0v :-)

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

      Bhiya scope of data science par ek video bano please

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

      🔥🔥

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

      bhaiya vo square root wale me Baar Baar SIGTERM output para hai kya cru

    • @swastikvasistha7488
      @swastikvasistha7488 2 ปีที่แล้ว

      #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

    • @rameshmalhotra9525
      @rameshmalhotra9525 2 ปีที่แล้ว

      th-cam.com/video/tAQIKe0UGH4/w-d-xo.html

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

    This is the best dsa series on TH-cam!!!!!
    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.

    • @x-Aryan.32
      @x-Aryan.32 3 หลายเดือนก่อน +3

      chal bhai age gyan mt pe***

  • @ishangrover1453
    @ishangrover1453 ปีที่แล้ว +4

    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.

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

      exactly..the one he used is for rotated array question

  • @rahulra9904
    @rahulra9904 10 หลายเดือนก่อน +3

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

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

    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

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

    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

    • @L.Lawliet_1618
      @L.Lawliet_1618 หลายเดือนก่อน

      if mid is the pivoted element?

  • @AbdulWahab-jl4un
    @AbdulWahab-jl4un ปีที่แล้ว +10

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

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

    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.❤️

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

    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

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

      Do not forget that he has also worked in amazon for 2 years

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

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

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

      bhai yehi likne ke liye aya tha scroll krta niche...these lines were Fr

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

    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

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

      placement hogyi?

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

      placement hogyi?

    • @understanding-why
      @understanding-why ปีที่แล้ว +8

      @@lalitsharma3137 haa 5000 rupay mahina. maine hi internship di h isko

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

      @@understanding-why 😂😂

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

      can u tell me why comparision takes place in 15;40 _ as s=4 and end =4 while statement doesnt satisfy here

  • @sudhanshusingh7200
    @sudhanshusingh7200 ปีที่แล้ว +16

    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
      @yashgupta6574 ปีที่แล้ว +1

      is it correct that pivot element is min or max element of an array?

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

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

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

    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.

    • @arjunyadav-kt5jr
      @arjunyadav-kt5jr 2 ปีที่แล้ว +6

      may be he didn't intend that!

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

      @@arjunyadav-kt5jr

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

      padle bhai bharat sarkaar free ki naukri nahi degi....khud hi karna h jo karna h

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

    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

    • @MohitNegi-r7d
      @MohitNegi-r7d 8 หลายเดือนก่อน

      aapne yhi question 40 min mai kiye ki dusre que 40 min mai kiye

    • @MohitNegi-r7d
      @MohitNegi-r7d 8 หลายเดือนก่อน

      please reply

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

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

    • @rvishal528
      @rvishal528 2 ปีที่แล้ว

      Yes✌️✌️✌️✌️✌️✌️✌️

    • @sjcreations2490
      @sjcreations2490 2 ปีที่แล้ว

      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.

    • @Nishad_Ranade1729
      @Nishad_Ranade1729 2 ปีที่แล้ว

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

    • @abhinavmishra9323
      @abhinavmishra9323 2 ปีที่แล้ว

      i just type the problem in google and leetcode in it and the first result is the leetcode problem. Hope this helps.

    • @rameshmalhotra9525
      @rameshmalhotra9525 2 ปีที่แล้ว

      th-cam.com/video/tAQIKe0UGH4/w-d-xo.html

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

    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

  • @rockinhitzz8682
    @rockinhitzz8682 ปีที่แล้ว +11

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

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

      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)

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

      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.

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

      @@deepbhatia_1511 also it won't hold true for 3 as well, as root 3= 1.732 and 3/2=1.5 ....

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

    We all are with you bhaiya. please be constant till the end. Your way of teaching is excellent.

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

    Truly Great series sir, You have truly helped me overcome my fear of DSA.
    Thank You very Much.

  • @govindsuryavanshi6653
    @govindsuryavanshi6653 ปีที่แล้ว +11

    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🙇‍♂

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

      Congratulations for the completion bro 🎉❤

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

      are you placed

  • @Happiness-BellaAndCookie
    @Happiness-BellaAndCookie ปีที่แล้ว +7

    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?

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

      well the second approach can be done by using the if condition nums[start]

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

    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
    }

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

      If it is not rotated then use binary search algorithm since it is increasing Order

  • @motivation_with_harsh
    @motivation_with_harsh ปีที่แล้ว +11

    //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]

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

    in 15:47 start and end both pointing at 4, so the loop stop here only as in while condition (s

  • @akshaysingh548
    @akshaysingh548 ปีที่แล้ว +25

    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]

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

      we can also use this
      int start=0,end=size-1,mid;
      while(startarr[end])
      start=mid+1;
      else if(arr[mid]

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

      faced this exact problem. thanks.

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

      the code for this problem( search in rotated sort array) given on gihub gives compilation error...is it with everyone?

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

      For that you can use the following condition in the beginning itself:-
      if(arr[0]

    • @SumitRathore-k3e
      @SumitRathore-k3e 3 หลายเดือนก่อน

      TLE aarha

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

    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 👌 💪 🙂 👏 🙌

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

    Explaining T.C. and S.C. of all the problems after soln. will be very helpful

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

    ATTENDANCE MARKED, VISITED RELEVEL, MADE NOTES, SOLVED QUESTIONS, LIKED THE VIDEO, EXITED WITH A SMILE.

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

    BEST TEACHER AWARD GOES TO YOU BHAIYA😇

  • @arpit441
    @arpit441 7 หลายเดือนก่อน +4

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

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

    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;
    }

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

      can u tell me why comparision takes place in 15;40 _ as s=4 and end =4 while statement doesnt satisfy here

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

      @@arnobbaiga309 sir ne ek step aur lga de galti sai
      actually it dont take olace

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

      @@rahulgopalka2403 right!!

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

    Present sir.... Your student josh is always high for the exciting class of DSA#lovebabbar

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

    This series is very helpful; thanks a lot ❤️

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

    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

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

      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

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

      Nested for loops bro... 😐😐😐

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

    t's my humble request please maintain this consistency till end. We all are with you bhaiya. Sab ek sath placed honge👍and thankyou

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

      can u tell me why comparision takes place in 15;40 _ as s=4 and end =4 while statement doesnt satisfy here

  • @VivekSingh-dw1do
    @VivekSingh-dw1do ปีที่แล้ว +1

    Search in rotated sorted array brute force solution:-
    int search(vector& arr, int n, int k)
    {
    for(int i =0; i

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

    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.

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

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

    • @RohitKumar-zd2hu
      @RohitKumar-zd2hu 2 ปีที่แล้ว +1

      Exactly you can not apply binary search in an array without knowing 1st and last index of array

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

      // 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;
      }

    • @zisunvlogs2002
      @zisunvlogs2002 2 ปีที่แล้ว

      @@adarshtiwari2727 brother could you please explain me the Algo ??i can't solve it in leetcode

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

      can u tell me why comparision takes place in 15;40 _ as s=4 and end =4 while statement doesnt satisfy here

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

    For the last question, i.e. sqrt upto floating part, this also works:
    #include
    float sqrt(float num)
    {
    float left = 0;
    float right = num;
    float midpoint = (right+left)/2;
    float prev_mid = -35;
    while(leftnum)
    {
    right = midpoint;
    }
    else if((midpoint *midpoint)>num;
    std::cout

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

    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 .

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

      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

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

      @@anuragsrivastava1995 thank you for trying but you just made it worse for me 😂😂🙏🏽

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

      @@krishnaprabeesh2415 😂😂

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

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

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

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

  • @vanshhans21
    @vanshhans21 หลายเดือนก่อน +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 ....

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

    East or west, bhaiya is the best!

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

    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.

  • @s.hariharanreddy5439
    @s.hariharanreddy5439 2 ปีที่แล้ว +6

    MINIMUM ELEMENT IN AN SORTED AND ROTATED ARRAY-
    int findMin(int arr[], int n){
    //complete the function here
    if(arr[0]

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

      can u tell me why comparision takes place in 15;40 _ as s=4 and end =4 while statement doesnt satisfy here

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

    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

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

    Search an Element in a Sorted & Rotated array using Binary Search
    beat 100 percent without see and discuss answer , now feelling motivated

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

    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;
    }

    • @rahulpant2002
      @rahulpant2002 2 ปีที่แล้ว

      Code sahi run nahi kar raha bhai!!...

    • @shaheen-e-iqbal744
      @shaheen-e-iqbal744 2 ปีที่แล้ว

      bhai aapke code ki second and third condition wrong he.....

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

      can u tell me why comparision takes place in 15;40 _ as s=4 and end =4 while statement doesnt satisfy here

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

    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

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

    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!

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

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

  • @tusharsingh1915
    @tusharsingh1915 ปีที่แล้ว +4

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

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

      what's your update bro

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

      @@Codeycodee well right now I'm pursuing MCA from BHU and getting placed in my 3rd sem🫂

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

      @@Codeycodee what about you brother

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

      @@tusharsingh1915 update brother?
      got placed?

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

    good love this video.....become millionare soon bro

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

    Thank u bhaiya for giving such a great content 🥰🥰

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

    Bhaiya aap kamaal ho mazaa hi ajata hai ye quality Maine abhi tak kisi course main nahin dekhi

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

    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.

  • @PraveenKumar-lf8cr
    @PraveenKumar-lf8cr ปีที่แล้ว +1

    Not going to quit ...definitely i will complete this whole series properly babbar bhaiya

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

      so on which video u r on?

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

    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.

    • @rbrt8
      @rbrt8 2 ปีที่แล้ว

      broh, apka confusion solve hua if yes then mujhe v btayen plz

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

    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

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

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

    • @summitrawat1093
      @summitrawat1093 2 ปีที่แล้ว

      bhai pivot element hota kya h , plzz explain !!!!

    • @vanshajrathi1910
      @vanshajrathi1910 2 ปีที่แล้ว

      @@summitrawat1093 pivot = minimum element in rotated sorted array

  • @cricballer9718
    @cricballer9718 2 วันที่ผ่านมา +1

    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

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

    Quality of the content is great, please continue the work.
    Much appreciated!

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

      can u tell me why comparision takes place in 15;40 _ as s=4 and end =4 while statement doesnt satisfy here

    • @VIPULARORA-rh5uz
      @VIPULARORA-rh5uz ปีที่แล้ว

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

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

    maza aagay bhaayya ji . By watching you it keeps increasing my interest in dsa❤❤

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

    Hat's off to the dedication, every concept is crystal clear, commenting for better reach!!!

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

      can u tell me why comparision takes place in 15;40 _ as s=4 and end =4 while statement doesnt satisfy here

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

    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.

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

    Excellent stuff and loving this DSA series

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

    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

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

    Love you bro please be constant till the end keep sharing your knowledge May god bless you

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

      Love bhai how to write the code if the question is twisted

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

    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 ❤️❤️❤️❤️

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

    You are amazing bhai ❤❤. Just one Question can we find square root of float numbers too using binary search?

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

    Mast Samjhaya ha Bhaiyya Aapne. Maza aa gaya.
    On to the Next Video.
    14 Videos Completed. 135 more to go.

  • @Shivanand-49
    @Shivanand-49 2 ปีที่แล้ว +3

    लाजबाब जबरजस्त जिंदाबाद🙏🙏🙏

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

    All are going good...The way you present the lecture is excellent. Thank you so much for this DSA course

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

    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?

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

      Approch 2:
      int start = 0, end = n - 1;
      int mid;
      while (start

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

    Samajh toh aa raha hai but I think I need to practice these questions few times in a single week !!! Thank you

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

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

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

    Over powered -------> Babbar Bhaiya

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

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

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

    Square Root of an Integer
    int floorSqrt(int n)
    {
    int s=1; // take it from 1 because all postive integer's root at least one not 0
    int e=n;
    int ans =1;
    while(s

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

    Just completed the video explanation with the graph of pivot was soo good.
    Akri thak data raha 🎉

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

    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;

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

      but complexity will be O(n) right?

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

    Search in a Rotated and Sorted Array problem !
    Another approach:
    int Search(vector& arr, int n, int k)
    {
    // Return the position of K in ARR else return -1.
    int start = 0;
    int end = n-1;
    // int mid = start +(end - start) /2;
    while(start

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

      thanks, sir wali approach mein problem thi 🙏

  • @RohitRana-tz2lr
    @RohitRana-tz2lr 2 ปีที่แล้ว +2

    I am strongly following you bhaiya.... Thanks, bhaiya for your efforts. This is my consistent 14th lecture.

  • @venkateshpk7822
    @venkateshpk7822 10 หลายเดือนก่อน +1

    Precision finding was absolutely awesome
    You really deserve more views and likes

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

    ksm s mja hi aa jata h bhai yr lecture dekh k...I appreciate u with bottom of my heart!...keep doing the good work.
    best wishes.
    p.s. I'm rewatching this series :)

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

      just appreciate it with the your back bottom he wiill be happy

  • @JackSparrow-z8s
    @JackSparrow-z8s ปีที่แล้ว

    you are the best teacher for DSA babbar bhaiya ,
    thank to that friend who recommended your channel for DSA

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

    Is find pivot in an array question (In this Video)
    is wrong???
    Because I searched on Google and got definition of pivot array that 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.
    I am so confused 😕
    Edit - I think bhaiya is discussing find pivot Index in sorted and rotated array and mistakenly tell that he is answering find pivot in an array.

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

    bhaiya pivot array to google pr kuchh aur hi dikh rha h
    An element in an array is a pivot element if the sum of all the elements in the list to its left is equal to the sum of all the elements to its right. EX : {1,2,3,7,6} here 7 is pivot element as 1+2+3 = 6

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

    if only he's a professor in college, then that college would be happiest place on earth --(big fan bhai🖤🖤)

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

    East to West Love Babbar Bhaiya is the best ❤️🙇

  • @dhruvjoshi8020
    @dhruvjoshi8020 2 ปีที่แล้ว

    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.

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

    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 ❤️

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

    Commenting before completing the video, kyoki ye series mae maza aa raha hai😁 and for better reach

  • @vishalvaishnav8846
    @vishalvaishnav8846 2 ปีที่แล้ว

    world best free course of DSA thank you Bhai Costly content ko Free me dene ke liye❤❤

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

    This course is best course for improving the problem solving in DSA

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

    One hour and I am going to say that you are a great teacher

  • @therealartist9
    @therealartist9 8 หลายเดือนก่อน +1

    search a element wala question aap agar vs code par karte to uske syntax ko likhne mai prolem nhi hoti but apney usko leetcode par solve kiya ab uske syntax solve karne mai bhot errors aa rahe hai bhaiya pls help

  • @princechorasiya6786
    @princechorasiya6786 8 หลายเดือนก่อน +1

    this fails at one edge case, when the array is not rotated or rotated by n elements v= [1,2,3] rotated by 3 [1,2,3] so look for the constraints in the question by how many places is the pivot rotated

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

    In the finding the pivot element basically we are finding the minimum of the elements in the array and then displaying the index right? so that could also be done simply by finding the minimum element and rerturning its index?

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

      is it correct that pivot element is min or max element of an array?

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

      yes but then you need to traverse the whole array and complexity will be O(n). Here, since we are doing Binary search, its O(log n). I think that's the only reason, otherwise yes, we are just finding the index at minimum value.

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

    Bhaiya apke vedio to jabardast hai hi kya hi kehna ,
    lekin jo vedio ke starting me codehelp ka logo ata hai uska background music bhi jabardast hai

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

    16:53 Sir Ap na yah jo pivot element ka code leakha hai es Array pay FAIL hogiya {50,1,60,70,80,90}
    It gives the last element which is wrong answer
    but the correct is second element

  • @atharvkumar2564
    @atharvkumar2564 2 ปีที่แล้ว

    bhaiya isse bhadiya content mujhe kahi nhi mila.I really your appreciate your efforts.Keep it up Bhaiya ji