Lecture 23: Binary Search Different Problem || Search Insert Position || Sqrt(x) || Count occurrence

Поділитися
Вставка
  • Опубліковано 25 січ 2025

КОМЕНТАРІ • 266

  • @CoderArmy9
    @CoderArmy9  Рік тому +106

    H/W sheet achee se kar lena❤

    • @vishalpratapsingh6994
      @vishalpratapsingh6994 Рік тому

      Ok bhaiya

    • @amankumaramar271
      @amankumaramar271 Рік тому +1

      1:10:00
      Thank you so much Bhaiya
      //count zero in given array which consists only 1 and 0
      int countZeroes(int arr[], int n) {
      // code here
      int count=0;
      for(int i=0;i

    • @nikhil316_pspk
      @nikhil316_pspk Рік тому

      ok bhai

    • @freetime3944
      @freetime3944 3 місяці тому

      Chamka bhaiya

  • @KaranKumar-bh1ij
    @KaranKumar-bh1ij Рік тому +7

    00 q1, 21:14 its code, 26:17 q2 40:47 its code, 42:00 sqrt question 1:00:26 its code 1:07:00 Homework questions

  • @sanjanad267
    @sanjanad267 7 місяців тому +27

    I have tried a lot of courses..... But everyone is telling a concept verbally and directly write the code...... Neither they dry run nor they tell how the loop is iterating.... 🥺❤ ..

    • @K-lz3wu
      @K-lz3wu 3 місяці тому +2

      These are the basics of C++ , you should have a good command over c++ to learn dsa in c++.

  • @mananbatra3274
    @mananbatra3274 4 місяці тому +3

    At 1:03:00 , we can initialize "mid" as long long rather than int. This will resolve all errors automatically.

  • @atifmalik8012
    @atifmalik8012 3 місяці тому +1

    27:33
    class Solution {
    public:
    int searchInsert(vector& nums, int target) {
    int start =0,end =nums.size()-1;
    int mid;
    while(start

  • @hi00010
    @hi00010 Рік тому +9

    36:46 we can directly print "first"
    Because first will hold the possible index value of the not found element 👍

  • @narutodihargo
    @narutodihargo Рік тому

    00:00= Q1) First & Last position of an element in an Array, 04:25=When to use Linear search & Binary Search, 21:16= Leetcode platform,

  • @thriveforsuccess27
    @thriveforsuccess27 11 місяців тому +30

    bhaiya logic banana aur implement karna , vo chotey chotey points ko dimaag mein rakhna ab kaafi default sa lagney laga hai aapki videos dekhkar .... thank you for the efforts bhaiya

    • @dontreadmybanner2002
      @dontreadmybanner2002 4 місяці тому

      Matlab

    • @rajtiwari8539
      @rajtiwari8539 3 місяці тому

      Bhai ye default kyo kah rahe h, mere samajh me aa raha h sir jo padhate h, aapka review kya h plz batayiga ​@@dontreadmybanner2002

  • @tusharagarwal5306
    @tusharagarwal5306 7 місяців тому +13

    2nd question(search insert position) me normal binary search bhi use karr sakte hai bas end me -1 ki jagah start return karna hoga.

    • @theabvpan09
      @theabvpan09 Місяць тому

      Mere leetcode mai kuch nahi return karne se bhi sahi ho raha hai

  • @rxi-geek
    @rxi-geek Рік тому +8

    Thankyou Rohit Bhaiya, you explain every topic very patiently and step by step. Amazing Lecture 🥰

  • @RonakAnand-gq2ur
    @RonakAnand-gq2ur 18 днів тому +2

    1:03:57 we can also do long mid = start+(end-start)/2

    • @xavdok
      @xavdok 17 днів тому +1

      I am facing time limit exceeding issue, what should I do ?

    • @RonakAnand-gq2ur
      @RonakAnand-gq2ur 17 днів тому +1

      @xavdok check condition of loop

  • @joydeep-halder
    @joydeep-halder Рік тому +6

    45:50 The time complexity is sqrt(n)

    • @Jv_Singh37
      @Jv_Singh37 Рік тому

      explain how ?

    • @joydeep-halder
      @joydeep-halder Рік тому +4

      @@Jv_Singh37 Because at maximum the number of iteration will go till sqrt(n). Let's say 25, then you start checking from 1, then 2, then 3, then 4, then 5, after that, if you want to go one step ahead i.e more than sqrt(25), then that square will exceed 25.

    • @Jv_Singh37
      @Jv_Singh37 Рік тому

      @@joydeep-halder u r talking about binary search ?

  • @procrastinator0811
    @procrastinator0811 Рік тому +3

    sabkuch chamak ra bhaiya. Keep continuing the good work.

  • @Jv_Singh37
    @Jv_Singh37 4 місяці тому

    00:01 Find First and Last
    26:08 Insert Position
    43:22 Sqrt(x)

  • @ManishKumar-d9b3j
    @ManishKumar-d9b3j 6 місяців тому +4

    Ram Ram Rohit bhai series bahut baddiya chal rahi hai aur sab kuch chamak raha hai apki wajah se best DSA corse on the internet thanks for the GOAT content man love&&respect++;

  • @sumitvishwakarma1075
    @sumitvishwakarma1075 Рік тому +9

    I was stuck on the sqrt(n) problem when you gave that in hw so when I checked the solution people were solving it using binary search but was not able to understand the code then but now
    I think it will be made crystal clear by you bhaiya .
    Thankyou bhaiya ❤❤

    • @ddoy7378
      @ddoy7378 Рік тому +1

      didn't got the answer kindly please explain

  • @joydeep-halder
    @joydeep-halder Рік тому +5

    Solution 5: Count zeroes ✅✅
    int start = 0, end = n-1, mid, firstIndex = -1;
    while(start

  • @chinmayOP
    @chinmayOP Рік тому +4

    Bhaiya i watch your videos daily with ongoing college and it will definitely give me an edge in Future so thank you and keep this going❤️

  • @Sajal_Mallick_vlogs
    @Sajal_Mallick_vlogs 10 місяців тому

    Day 31 done and dusted...... Awesome explaination...... #consistency

  • @joydeep-halder
    @joydeep-halder Рік тому

    26:03 Optimization to Find First and Last Position of Element in Sorted Array 🚀🚀
    We can check the adjacent left or right element matching or not, and this way we can avoid unnecessary search in left and right subarray.
    class Solution {
    public:
    vector searchRange(vector& nums, int target) {
    int firstIndex = -1, lastIndex = -1;
    int start=0, end = nums.size() - 1, mid;
    while(start

  • @shubhampathak7667
    @shubhampathak7667 21 годину тому

    1:03 pe hm int mid ko long mid kr denge to sb sai ho jaega...no need for extra if statement...
    bhaiya ye ni kr skte h kya??

  • @shubhamlipane8634
    @shubhamlipane8634 6 місяців тому +2

    Lecture 23 Completed On 16-07-2024

  • @SunnyKadian1
    @SunnyKadian1 Рік тому +3

    In Every video there is something new to learn. ❤❤❤❤

  • @atifmalik8012
    @atifmalik8012 3 місяці тому

    49:42
    class Solution {
    public:
    int mySqrt(int x) {
    if(x==0||x==1)
    return x;
    int start = 1,end = x/2,mid,ans;
    while(start

  • @asad_iliyas
    @asad_iliyas Рік тому +6

    Thanks bhaiya for this amazing course

  • @abhaydeep3070
    @abhaydeep3070 Рік тому +5

    Bhaiya i am in class 9th and your teaching methods are so good that i got to know every topic crystal clear . I am watching your videos from day 1 and i will definitely complete the 180 challenge
    By Abhay Deep

    • @devprajapati5673
      @devprajapati5673 7 місяців тому +2

      beta boards par focus kro ye kha aagye ho aap.

    • @abhaydeep3070
      @abhaydeep3070 7 місяців тому +2

      @@devprajapati5673 skill zyada imp h boards se

    • @dontreadmybanner2002
      @dontreadmybanner2002 4 місяці тому

      ​@@devprajapati5673bhai feka raha hai vo

    • @dontreadmybanner2002
      @dontreadmybanner2002 4 місяці тому

      ​@@devprajapati5673sahi bola bhai yisko malum nahi coding round ke phele amplitude round hota hai

    • @devprajapati5673
      @devprajapati5673 4 місяці тому

      @@dontreadmybanner2002 yup

  • @joydeep-halder
    @joydeep-halder Рік тому +3

    HW Solution 4: Kth missing postive integer. ✅✅
    int start = 0, end = arr.size()-1;
    while (start

  • @sheetalsharma1675
    @sheetalsharma1675 5 місяців тому

    Aapne youtube pr sbse best pdya ..ithe sare questions bhot ache smajae...

  • @AnshuKumari-gz7ju
    @AnshuKumari-gz7ju 14 днів тому

    Thank u Bhaiya apki wajah se meri DSA acchi ho gai hai..

  • @atifmalik8012
    @atifmalik8012 3 місяці тому

    1:09:54
    //Count occurrences
    class Solution{
    public:
    /* if x is present in arr[] then returns the count
    of occurrences of x, otherwise returns 0. */
    int count(int arr[], int n, int x) {
    int first = -1,last = -1,mid;
    int start = 0,end = n-1;
    while(start

  • @atifmalik8012
    @atifmalik8012 3 місяці тому

    2:19
    class Solution {
    public:
    vector searchRange(vector& nums, int target) {
    vectorans(2,-1);
    if(nums.size() == 0)
    return ans;
    int start = 0,end = nums.size()-1;
    int mid;
    while(start

  • @Gyanendra012
    @Gyanendra012 4 місяці тому +1

    Question - 2 34:00 crux of this problem is " target says:- merse badaa number may be mera position occupy kiya hua h so let me consider that in my answer variable aur merse chhote number se mujhe koi dikkat nhi h"

    • @Billy-gd1rm
      @Billy-gd1rm 4 місяці тому

      Bhai count occurence ka code bata do ? Mera error aa rha hn😢

    • @Gyanendra012
      @Gyanendra012 4 місяці тому

      @@Billy-gd1rm Bhaiya ne bahut achhe se samjhaya h. ek baar aur rewind kar ke dekho...
      Basically is question me two times binary search lagana h one for first and one for last...
      do these steps for both the search :
      1. apply binary search and find the target element and consider in the answer.
      2. Don't terminate the loop find in left and right for respective reaches.
      3. keep finding till while loop end.
      4. This will give you leftmost and rightmost index of that element for the respective search
      this is the code you may refer :
      //User function template for C++
      class Solution{
      public:
      /* if x is present in arr[] then returns the count
      of occurrences of x, otherwise returns 0. */
      int count(int nums[], int n, int target) {
      // code here

      //first occurance

      int start=0,end=n-1,mid=0,first_index=-1;
      while(start

    • @Gyanendra012
      @Gyanendra012 4 місяці тому

      @@Billy-gd1rm explain the error
      you can refer this code:
      //User function template for C++
      class Solution{
      public:
      /* if x is present in arr[] then returns the count
      of occurrences of x, otherwise returns 0. */
      int count(int nums[], int n, int target) {
      // code here

      //first occurance

      int start=0,end=n-1,mid=0,first_index=-1;
      while(start

    • @Gyanendra012
      @Gyanendra012 4 місяці тому

      @@Billy-gd1rm i have reply 2 times but i don't know why its deleted autometically

    • @Gyanendra012
      @Gyanendra012 4 місяці тому

      ohh got it.. i wrote the code here which is why it deleted...
      what the error you are getting?

  • @SoveerShah
    @SoveerShah 3 місяці тому +1

    1:05:00
    just asign ans = 0 while declaring.

  • @pratapkumar7249
    @pratapkumar7249 11 місяців тому +1

    bhaiya aap se ek request tha ki jab aap questions batate hai toye bhi bata diya kariye kaun kaun si company me pocha gaya hai

  • @thorff7423
    @thorff7423 Рік тому +2

    Thank you so much bro❤❤❤. Aap hamare liye 3 baje lecture record karte ho ...❤❤❤

  • @I_am_loki_of_asgard988
    @I_am_loki_of_asgard988 7 місяців тому

    Sqrt(n) wala phela code hua jo mai thoda apka logic dekh ke khud se banaya aur khud se samjh gaya ki isme errors aayenge toh usko kaise handle krna h INT MAX ka output kaise print krwana h ❤
    Thanx bhaiya apki videos se sirf theory nhi balki bohot logic lagana bhi sikh rha hu padhai me bhi itna logic nhi laga pata 😂😂

  • @I_am_loki_of_asgard988
    @I_am_loki_of_asgard988 7 місяців тому

    1:03:17 yes bhaiya aur maine phle hi samjh gya tah🥳🥳 thnku bhaiya

  • @MahiiiImran
    @MahiiiImran 4 місяці тому

    Your teaching style is amazing😊

  • @mr.perfect7925
    @mr.perfect7925 9 місяців тому +1

    In square root question why not simply initialize mid variable with double.
    I did it and it passed smoothly

    • @nikhilgupta000
      @nikhilgupta000 8 місяців тому +1

      Brother kya tum leet code pr question solve krte ho??
      Subscription le rkha h leetcode ka???

    • @mr.perfect7925
      @mr.perfect7925 8 місяців тому +1

      @@nikhilgupta000 solve karta hu but subscription nahi lia hu

    • @nikhilgupta000
      @nikhilgupta000 8 місяців тому

      @@mr.perfect7925 kaise kra h brother
      Mujhe bhi janna h

    • @mr.perfect7925
      @mr.perfect7925 8 місяців тому

      @@nikhilgupta000 follow striver sheet

  • @abiralaminn
    @abiralaminn 11 місяців тому

    Congratulations bro for 100k , I'm with you when it was 64k

  • @seema4014
    @seema4014 6 місяців тому

    excellent teaching for develop code and i thought no any one better than u sir❤

  • @faizanahmed9304
    @faizanahmed9304 Рік тому

    bhaiya aapne toh arrays pe zada problems nahi karaye kya aap woh baad mein kariynge kya?

  • @joydeep-halder
    @joydeep-halder Рік тому +1

    Solution 7: Cube root of a number.
    if(N

  • @ashutosh4129
    @ashutosh4129 7 місяців тому

    best explanation i have seen on binary search.

  • @indian_gaurav_8648
    @indian_gaurav_8648 Рік тому

    bhiya sqrt wale q me jab hum (mid * mid ) karenge to wo int ki upper limit k bhr b to jaa skta h naa
    PS :- ha aapne cover krdiya wo cheeej baad me sry mene dekha nahi tha

  • @AK_aka_AK
    @AK_aka_AK 9 місяців тому

    00:00 Fint First and Last element in a sorted array
    09:11 Code part of First and Last Element

  • @GOATSOFFOOTBALL
    @GOATSOFFOOTBALL 9 місяців тому

    20:40 t.s
    26:20 seond question

  • @Shauryousee
    @Shauryousee 6 місяців тому

    bhaiya time complexity for the linear approach of the root funcn is root n right..?

    • @Shauryousee
      @Shauryousee 6 місяців тому

      and yes bhaiya graphically ek baat aur sochi ki rootn ka graph is always above lnx thus time complexity ke terms mein binary search lagana is better

  • @baibamashu9926
    @baibamashu9926 Рік тому

    Bhaiya dout support ka kya hua!??
    Mene multiple times aa same chiz comment bhi ki different videos pe pr koi reply nhi aata.
    Mene subscription liya hua hai pr jo links aape provide kiya he bo khulte nhi or aap new link provide krbate nhi mene aase a aspect nhi kiya tha!

  • @AdityaSharma-jx6yc
    @AdityaSharma-jx6yc Рік тому

    In second question of search insert position can we return start after running the whole while loop then by checking the condition if start > end , in case if the element is not found . Then also our problem will be solved

  • @manthanramteke6101
    @manthanramteke6101 11 місяців тому

    Sir you have great problem solving skills 😊

  • @therohitgarg
    @therohitgarg Рік тому

    Bhaiya in 2nd Q initially I took index= -1 ...and rest of the code is same but when si=mid+1 , I updated the as index =si; means mid pr to possible nhi h but mid+1 pr to ho skta h na.....so is it a correct approach???

  • @mdsohanurrahmanhridoy1343
    @mdsohanurrahmanhridoy1343 Рік тому +2

    ✅Completed_Lecture23....19-Nov-2023

    • @ramjikumar2366
      @ramjikumar2366 7 місяців тому

      Bhai tu world Cup ke din bhi padh rha tha Khair jane de purana jhakm taja kar diya😭

  • @RahulSingh-t7i6v
    @RahulSingh-t7i6v 4 місяці тому

    Bhaiya Vs code me kese solve kre while loop 2 baar likhna h kya

  • @sagardebnath8842
    @sagardebnath8842 Рік тому

    Bhaiya can we take our mid long long instead of int?

  • @MohammedHasmi577
    @MohammedHasmi577 9 місяців тому

    45:50 Time Complexity is O(root N)

  • @sidheshwarsharma3437
    @sidheshwarsharma3437 Рік тому +1

    Day 31 of #180DaysOfCode completed
    In Today's class, the observation is that how much is essential to get the approach first and then code because all the game of approach code written can be done in a few minutes.

  • @MayureshDagale-sg6op
    @MayureshDagale-sg6op 4 місяці тому +1

    K th missing number using linear search .
    code :
    #include
    using namespace std;
    int main(){
    int size , arr[100] , k;
    cout > size;
    cout arr[i];
    }
    cout > k;
    int n=0 , i=1;
    while(n

  • @abhinayjangde
    @abhinayjangde 5 місяців тому

    27:24 bhaiya maine ise min heap se solve kiya hai
    int searchInsert(vector& nums, int target) {
    // min heap
    priority_queue pq;
    for(int i=0; i

  • @harshkumar7686
    @harshkumar7686 Рік тому

    Bhaiya Square root wale question ki linear approach ki Time Complexity O(root(n)) hogi

  • @512_jee51
    @512_jee51 2 місяці тому

    at 55:00 ....
    class Solution {
    public:
    int mySqrt(int x) {

    return sqrt(x);
    }
    };
    simple 😂

  • @Shauryousee
    @Shauryousee 6 місяців тому +1

    MY APPROACH FOR THE SEARCH INSERT POSITION
    int n=nums.size();
    int start=0,end=n-1;
    int mid;
    while(starttarget)
    {
    end=mid-1;
    }
    else
    {
    start=mid+1;
    }
    }
    if(nums[mid]>target)
    return mid;
    else
    return mid+1;

    • @Shauryousee
      @Shauryousee 6 місяців тому

      my mathematics teacher used to say one thing
      "apni walil sabko achhi lagti hai"
      although aapka metjod was easier to understand but apna method sabko best lagta 😂😂❤

  • @sonumondal7798
    @sonumondal7798 Рік тому

    Bhaiya aap bahut hi ache se samjha te ho bas aise hi 180 day tak chamkate rehna 😅😅❤

  • @Harikesh662
    @Harikesh662 Рік тому

    Index= mid+1 bhi kr sakte the jab Target value bada ho

  • @learnprogrammingtip665
    @learnprogrammingtip665 4 місяці тому

    square root
    int main()
    {
    int num;
    coutnum;
    int start=1,end=num;
    int mid,index;
    while(startnum)
    {
    end=mid-1;
    }
    if(mid*mid

  • @harshyadav1214
    @harshyadav1214 10 місяців тому +1

    Thanks for explanation . amazing

  • @yes-its-goliya
    @yes-its-goliya 7 місяців тому

    🏃‍♀Day 8✅
    Thank you so much bhaiya for this great work...

  • @_hulk748
    @_hulk748 Рік тому

    Great Explanation Sir🙏🙇‍♂✨✨💖💖

  • @yashwantchoure
    @yashwantchoure 7 місяців тому

    Solved All 7 Questions given in the description.

  • @PrabhatKumar-c9f
    @PrabhatKumar-c9f 6 місяців тому

    sir while loop se mat kra kariye if else if more understanding than this

  • @startercoder
    @startercoder Рік тому

    Bhaiyya! Chamak gaya acchese✨✨

  • @visverthedepthofphysics6297
    @visverthedepthofphysics6297 11 місяців тому

    Can't tell, how good your course is?

  • @rhitam_biswas
    @rhitam_biswas 5 місяців тому

    August 3 : Day 3 of Revision
    Questions on Binary Search Done ✅✅✅

  • @GoogleSoftwareEnginear
    @GoogleSoftwareEnginear 11 місяців тому

    In 5 questions we found the first and last position of an array after doing this (first -last) + 1
    And get the desired output 🎉🎉😊

  • @musaifbangi8705
    @musaifbangi8705 6 місяців тому

    Another best way to not have error is mid=start/2 +end/2

  • @simransahani9199
    @simransahani9199 2 місяці тому +1

    raapchik content ,guyz pls do share with your frnds, bcz likes != 💎💎📄📄,so please like and subscribe after watching the vdos of neggi bhaiya❤❤

  • @souravsanyal7154
    @souravsanyal7154 11 місяців тому

    valo explain korle rohit da

  • @coding24335
    @coding24335 3 місяці тому

    Great sir❤

  • @rohitvhanmore8742
    @rohitvhanmore8742 Рік тому

    Bhaiya second wala questions k 36 test cases he pass horahe hain sirf .

  • @Radhe55
    @Radhe55 3 місяці тому

    Bhaiya Maza++ ❤

  • @AlapanPal
    @AlapanPal 9 місяців тому

    26:20 second question

  • @Manav00121
    @Manav00121 Рік тому

    sqrt of x by using normally loop time_complexity:- O(n).

  • @user-ritesh92
    @user-ritesh92 4 місяці тому

    mere me TLE aa rha h same logic se aisa kyu ??

  • @ankushladani496
    @ankushladani496 Рік тому

    Done Bhaiya... 31/180 ✅

  • @RJFF3-r7w
    @RJFF3-r7w 7 місяців тому

    Pura chamka diya bhaiya🤩

  • @mdakram8080
    @mdakram8080 Рік тому

    Where is discord link ?

  • @omyele9315
    @omyele9315 Рік тому

    Time complexity o(n) hai na. 45:45

    • @maniishbhandari
      @maniishbhandari 11 місяців тому

      I think O(sqrt(n)) hogi kyuki hum bs sqrt n wle element ko lere hai

  • @Vikash_chauhan_vkc
    @Vikash_chauhan_vkc 7 місяців тому

    saach bolu to aisa content abhi youtube me aya hi ni hai fadu level ka concept koi hau ni takar me apka bhaiya
    2 cr package bande ne aise hi ni phod rakha hai

  • @Knox_47
    @Knox_47 Рік тому

    Thank you Bhaiya
    aaj Bahot maja aaya.

  • @tushargupta1867
    @tushargupta1867 11 місяців тому

    Amazing lecture

  • @amanraj7467
    @amanraj7467 2 місяці тому

    Ram Ram bhaiya maja aa gaya

  • @pagl_panti-vlog.12
    @pagl_panti-vlog.12 Рік тому

    Bhaiya we can easily write the program of square root like this
    #incude
    #include
    Using namespace std;
    Int main ()
    {
    Int n;
    Courtn;
    Int a=sqrt(n);
    Court

    • @sathwikakurma6496
      @sathwikakurma6496 4 місяці тому

      there is a condition not to use in built operations

  • @GayatriShejule-o1k
    @GayatriShejule-o1k 19 днів тому

    Thank you so much sir🥰

  • @animeshkumarsingh4291
    @animeshkumarsingh4291 Рік тому

    #180DaysofCode
    Day -31/180 Lecture -23
    Successfully Completed ✅✅✅

  • @sanjanad267
    @sanjanad267 7 місяців тому +2

    Anyone for pair prograaming???

  • @devvariya4826
    @devvariya4826 4 місяці тому +1

    int arr[7]={1,2,3,3,4,5,3};
    int n=sizeof(arr)/sizeof(arr[0]);
    int i=0 , j=n-1 , x , fp=-1 , lp=-1;
    coutx; cout

  • @-BCS-VarshaVaishnav
    @-BCS-VarshaVaishnav Рік тому

    31/180 done , thanku so much bhaiya

  • @riteshbhadana
    @riteshbhadana Рік тому

    bhai kabhi kabhi time dekha diya jise hum motivate bhi hogye kre ki bhai itne late tak humre liya mehant kr te hai

  • @abdxlive
    @abdxlive 7 місяців тому +1

    26 June ❤ Completed

  • @Blackshadow-K
    @Blackshadow-K 4 місяці тому

    count zero
    int countZeroes(vector &arr) {
    // code here
    int mid;
    int start =0;
    int end =arr.size()-1;
    int ind;
    while(start0){
    start =mid+1;
    }
    else{
    ind =mid;
    end =mid-1;
    }
    }
    return (arr.size())-ind;
    }

    • @Billy-gd1rm
      @Billy-gd1rm 4 місяці тому

      Bhai count occurence ka code bata do ? Mera error aa rha hn😢