Count Elements in Two Arrays | GFG Solution | Searching and Sorting

Sdílet
Vložit
  • čas přidán 9. 06. 2021
  • Please consume this content on nados.pepcoding.com for a richer experience. It is necessary to solve the questions while watching videos, nados.pepcoding.com enables that.
    NADOS also enables doubt support, career opportunities and contests besides free of charge content for learning. Question Statement:
    Given two unsorted arrays arr1[] and arr2[]. They may contain duplicates. For each element in arr1[] count elements less than or equal to it in array arr2[].
    Topic: #BinarySearch #GFG #SearchingAndSorting
    Used #DataStructure: #Array
    #TimeComplexity: O(nlog(m)) , where n is the size of first array and m is the size of second array.
    #SpaceComplexity: O(1)
    ----------------------------------------------------------------
    For detailed information and other exercises, VISIT: www.pepcoding.com
    Have a look at our result: www.pepcoding.com/placements​
    Follow us on our FB page: / pepcoding​
    Follow us on Instagram: / pepcoding​
    Follow us on LinkedIn: / pepcoding-education
    ----------------------------------------------------------------
    #Array #leetcode #GFG #SearchingAndSorting #BinarySearch
    For a better experience and more exercises, VISIT: www.pepcoding.com/resources/
    Have a look at our result: www.pepcoding.com/placements
    Follow us on our CZcams page: / pepcoding
    Follow us on our FB page: / pepcoding
    Follow us on Instagram: / pepcoding
    Follow us on LinkedIn: / pepcoding-education
    Follow us on Pinterest: / _created
    Follow us on Twitter: home
    .
    .
    .
    Happy Programming !!! Pep it up 😍🤩
    .
    .
    .
    #pepcoding #code #coder #codinglife #programming #coding #java #freeresources #datastrucutres #pepcode #competitive #competitiveprogramming #softwareengineer #engineering #engineer

Komentáře • 27

  • @sujan_kumar_mitra
    @sujan_kumar_mitra Před 2 lety +5

    The Prefix Sum and Frequency technique is quite intuitive. Thanks for the explanation.

  • @travelJS
    @travelJS Před 3 lety +6

    Quality explanation mam cleared all the concepts.

  • @riamonga2283
    @riamonga2283 Před rokem

    More solution vids from Manish Ma'am 🙌🙌🙌🙌🙌🙌

  • @abhishekkumarkamti2183
    @abhishekkumarkamti2183 Před 2 lety +1

    Great explanation ma'am ❤❤

  • @danishrockz1
    @danishrockz1 Před 3 lety +1

    super madam

  • @16avikasgupta70
    @16avikasgupta70 Před rokem

    My mind was blown away by second approach

  • @akatsuki1363
    @akatsuki1363 Před 2 lety +1

    Best👌👌

    • @Pepcoding
      @Pepcoding  Před 2 lety

      Glad you liked it!
      Keep learning.
      And for better experience and well curated content explore nados.pepcoding.com

  • @ShivamGupta-cx3hy
    @ShivamGupta-cx3hy Před 3 lety

    Thank you so much maam

  • @dheerajchhatani7610
    @dheerajchhatani7610 Před 3 lety

    NEXT LVL

    • @Pepcoding
      @Pepcoding  Před 3 lety

      I am glad you liked it. I also hope that you are watching till end and trying to understand the what, how and especially why of the problem.
      If you like our efforts, we request a review
      g.page/Pepcoding/review?rc
      You can subscribe to our channel here
      czcams.com/users/Pepcodingabout?view_as=subscriber

  • @aditikajale8514
    @aditikajale8514 Před 3 lety +1

    in binary search can we find the last occurance of the given el and then add (last occ + 1) in count

    • @mickyman753
      @mickyman753 Před 2 lety

      we don't know the ele exist or not ,we will find last occ of

  • @vasugaur1283
    @vasugaur1283 Před 3 lety

    binary search wali approach me Arrays.sort ka (mlog(m)) bhi count hoga

    • @arshadmanxoori07
      @arshadmanxoori07 Před 2 lety

      it will be O(nlogm + mlogm) and we will consider higher one

  • @anulrajeev7891
    @anulrajeev7891 Před rokem

    Just another approach :
    vector getCount(vector A, vector B)
    {
    vector C=A;
    sort(A.begin(),A.end());
    sort(B.begin(),B.end());
    int i=0, j=0, m=A.size(), n=B.size();
    unordered_map mp;
    while(i

  • @sanyamagarwal5899
    @sanyamagarwal5899 Před 3 lety +1

    Mam or kitni videos aaegi iss series me ?

  • @anket_singh9003
    @anket_singh9003 Před 6 měsíci

    More questions atleast 50 more

  • @soumikchaudhuri7634
    @soumikchaudhuri7634 Před rokem

    Ma'am, would Freq array method work if both the arrays contains negative integers ?

  • @samadhanmhaske5900
    @samadhanmhaske5900 Před 3 lety

    Man aapake videos ki special playlist banaye

  • @imi9741
    @imi9741 Před 3 lety

    maam just becos of ur teaching i jv subscribed this channel

    • @Pepcoding
      @Pepcoding  Před 3 lety +1

      keep motivating, keep learning and keep loving Pepcoding😊

  • @taranjeetsingh3629
    @taranjeetsingh3629 Před 3 lety

    Mam we can also take psa array's length as max value of arr1. because we can search for that value at max in psa. Plz tell if I'm wrong

    • @jeevangautam4724
      @jeevangautam4724 Před 2 lety

      yes we can take psa length as max value from arr1 or arr2(whichever is max) + 1(for index handling)

  • @sanketsinha9816
    @sanketsinha9816 Před rokem

    More Optimized Approch
    .
    .
    int[] ans = new int[arr1.length];
    int max1 = Integer.MIN_VALUE;
    for(int i : arr1){
    max1 = Math.max(max1,i);
    }

    int max2 = Integer.MIN_VALUE;

    for(int i : arr2){
    max2 = Math.max(max2,i);
    }

    int omax = Math.max(max1,max2);

    int[]pre = new int[omax + 1];

    for(int i = 0 ; i < arr2.length ; i++){
    int key = arr2[i];
    pre[key] += 1;
    }

    for(int i = 1 ; i < pre.length; i++){
    pre[i] += pre[i-1];
    }

    for(int i = 0 ; i < ans.length ; i++){
    ans[i] = pre[arr1[i]];
    }

    return ans;
    .
    .
    .