Find a Pair with a Given Difference | Love Babbar DSA Sheet | GFG | FAANG🔥 | Placement

Sdílet
Vložit
  • čas přidán 18. 12. 2020
  • #sorting and searching #competitiveprogramming #coding #dsa
    Hey Guys in this video I have explained with code how we can solve the problem 'Find a Pair with a Given Difference'.
    Array question Playlist = • Love Babbar DSA 450 Qu...
    String question Playlist = • Love Babbar DSA 450 Qu...
    Searching and Sorting question Playlist = • Love Babbar DSA 450 Qu...
    Binary Tree question Playlist = • Love Babbar DSA 450 Qu...
    Dynamic Programming question Playlist = • Love Babbar DSA 450 Qu...
    Roadmap for Dynamic Programming = • Complete Roadmap for D...
    Great Strategy to solve DSA = • Great Strategy to solv...
    My Journey to 5 star at codechef = • My Journey to 5 Star a...
    Love Babbar DSA Sheet : drive.google.com/file/d/1FMdN...
    Follow us on Instagram:
    Shailesh Yogendra : / shaileshyogendra
    Yogesh Yogendra : / i_am_yogesh_here
    Follow us on Linkedin:
    Shailesh Yogendra : / shailesh-yogendra-8b13...
    Yogesh Yogendra : / yogesh-yogendra-26bbb518a
    Hope you like it. Comment if you have any doubt
    LIKE | SHARE | SUBSCRIBE

Komentáře • 26

  • @aniketshankar2924
    @aniketshankar2924 Před 2 lety +6

    Example Array - [1,3,2] and x=0; then as per your logic (1+0) that is 1 exists in the map .

  • @deepakajay4204
    @deepakajay4204 Před rokem +2

    Handling all the test cases😀😀
    //we can use hashing
    HashMap map = new HashMap();
    for(int i = 0; i < size; i++){
    map.put(arr[i], map.getOrDefault(arr[i], 0) + 1);
    }
    for(int i = 0; i < size; i++){
    int curr = arr[i];
    int pair = n + arr[i];
    if(n > 0 && map.containsKey(pair)){
    return true;
    }
    if(n == 0){
    //check for -curr
    if(map.containsKey(-1 * pair)){
    return true;
    }
    //one more edge case
    //check for same curr and count
    if(map.containsKey(pair) && map.get(pair) > 1){
    return true;
    }
    }
    }
    return false;

  • @prateeksomani5803
    @prateeksomani5803 Před 2 lety +7

    You haven't considered corner case for x=0

  • @anujsoni6089
    @anujsoni6089 Před 3 lety

    Bhot shi kaam kr rhe ho bhiyaa appp🔥🔥🔥

  • @ridhamgodha4569
    @ridhamgodha4569 Před 3 lety +3

    binary search method is not getting submitted on gfg

  • @yashyadav7927
    @yashyadav7927 Před 2 lety

    dude ur approach is good but we in constrain there is mentioned that we don't need to use extra space

  • @tombrady7390
    @tombrady7390 Před 3 lety +2

    edge case when all elements of array are same is not handled by method 2

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

      int Solution::solve(vector &A, int B) {
      unordered_map mp;
      for(auto i : A) mp[i] = 1;
      for(auto i : A){
      mp[i] = 0;
      if(mp[B+i] > 0) return 1;
      mp[i] = 1;
      }
      return 0;
      }

  • @princemathur2451
    @princemathur2451 Před rokem

    You are solving other question, the question given in love babbar sheet is present on coding ninjas

  • @stunnerhash
    @stunnerhash Před 3 lety +2

    map me insert karne ki time complexity logn hoti h shayad toh , second case me nlogn hogi time complexity , im not sure though

    • @CodeLibrary
      @CodeLibrary  Před 3 lety +2

      unordered map has O(1) complexity and Map has O(LogN) complexity...and I am using unordered map

    • @ekkranti4896
      @ekkranti4896 Před 3 lety

      @@CodeLibrary yeah you are right

  • @SajanKumar-ec2us
    @SajanKumar-ec2us Před 10 měsíci

    Uper bound kya hota hai.expliain clearly last method

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

    at 9:00 , upper bound etc is not there in java, kindly use methods which are generic, and not standard libraries for c or c++

    • @CodeLibrary
      @CodeLibrary  Před 2 lety

      You can create your own upper bound fn in java right ?

  • @sanjogbhalla1720
    @sanjogbhalla1720 Před 2 lety

    bhaiya apan -a kyu kar rahe hai upperbound function ke baad?

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

    3rd method 7:25

  • @googlePowerful452
    @googlePowerful452 Před rokem

    Not working for nlogn

  • @faizanahmad-oc4fw
    @faizanahmad-oc4fw Před 2 lety

    Bro give the source code in description

  • @trialaccount2244
    @trialaccount2244 Před 3 lety

    bhai + q ke rahe ho map[arr[i]]-x q nhi?

  • @user-jk7nb5ip3w
    @user-jk7nb5ip3w Před 9 měsíci

    tqqqqqqqqqqqqqqqqqqq

  • @navendraagrawal
    @navendraagrawal Před 2 lety

    this code is giving wrong answer you make fool in every video

  • @vaibhavchhabra800
    @vaibhavchhabra800 Před 2 lety

    It is pronounced as sorted not shorted

  • @saurabhsingh1608
    @saurabhsingh1608 Před rokem

    Failing for testcase :5 0
    1 2 2 6 5
    with method3 i tried on gfg.
    bool findPair(int arr[], int n, int k){

    bool flag=false;
    sort(arr,arr+n);
    if (k==0) return flag;
    for(int i=0;i