Common elements in 3 sorted arrays | Array | Love Babbar DSA Sheet | Hindi

แชร์
ฝัง
  • เผยแพร่เมื่อ 14 ต.ค. 2024

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

  • @shubhendupandey3124
    @shubhendupandey3124 3 ปีที่แล้ว

    As a beginner mujhse ye sheet bilkul nahi solve ho rha tha..par apka video dekh kar bhut help mil jata hai.I always keep on waiting for your video.Plz don't stop. Keep on going. Lots of love and respect 🙏🏻

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

      Thank you Shubhendu. This gives me motivation :)

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

    class Solution:
    def commonElements(self, A, B, C, n1, n2, n3):
    i, j, k = 0, 0, 0
    ans = []
    prev = float('-inf') # Track previous element to avoid duplicates
    while i < n1 and j < n2 and k < n3:
    if A[i] == B[j] == C[k] and A[i] != prev: # Check for common element and avoid duplicates
    ans.append(A[i])
    prev = A[i]
    elif A[i]

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

    Sister many people are already doing this love babbar sheet
    I request you to take a topic and explain your favourite questions on that topic in level wise so that it will help both you and us 🙋‍♂️🙋‍♂️
    Example dynamic programming bahut dikat lagta hei
    Try to do the solution in both top-bottom and bottom to top approaches
    Moreover I have seen your interview sister it was very happy to see you at coding ninjas ☺️☺️keep growing..

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

      Yes Akhil, nice idea. I will solve dp questions from this sheet both top-down and bottom-up approach

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

    Your way of explanation is very good. keep doing it. :) . I am able to write the code by myself when you explain the dry run very clearly.

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

    Nice initiative. In this way we will be able to solve all ques of Love Babbar sheet with your help. Keep them coming 🙂

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

    Hi, while dry running the algorithm you explained using the approach of smallest of 3 and in the code you compared 2 arrays like first starting with smaller of ar1 and ar2 then proceeding...when i used the approach of smallest of 3 in my code is showing output as -1 in some test case..pls help me out with it.My code is as follows:
    class Solution
    {
    public:
    vector commonElements (int ar1[], int ar2[], int ar3[], int n1, int n2, int n3)
    {
    int i = 0, j = 0, k = 0;
    vector ans;
    int prev1, prev2, prev3;
    prev1 = prev2 = prev3 = INT_MIN;
    while (i < n1 && j < n2 && k < n3) {
    while (ar1[i] == prev1 && i < n1)
    i++;
    while (ar2[j] == prev2 && j < n2)
    j++;
    while (ar3[k] == prev3 && k < n3)
    k++;
    if (ar1[i] == ar2[j] && ar2[j] == ar3[k]) {
    ans.push_back(ar1[i]);
    prev1 = ar1[i];
    prev2 = ar2[j];
    prev3 = ar3[k];
    i++;
    j++;
    k++;
    }
    else if (ar1[i] < ar2[j] && ar1[i] < ar3[k]) {
    prev1 = ar1[i];
    i++;
    }
    else if (ar2[j] < ar1[i] && ar2[j] < ar3[k]) {
    prev2 = ar2[j];
    j++;
    }
    else {
    prev3 = ar3[k];
    k++;
    }
    }
    return ans;
    }
    };

    • @tarunkumar.d8379
      @tarunkumar.d8379 2 ปีที่แล้ว

      Hi , due to lazy condition check in cpp, while loop mein i

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

      @@tarunkumar.d8379 I Didn't get you.. Pls explain clearly..

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

    Actually while explaining you have taken min of three and incremented the min one, but in the line 40 you are just comparing with the element in first array and element in 2nd array?

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

    Hello mam, really loving your explanations. I wanted to ask that how do i find the approach of questions. Like now i have learned the approach here but i am not able to find the approach by myself for most of the question.. so do i need to learn the approach of every type of question and then practice??

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

      I also have the same question what you did to improve?

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

    Wow ma'am great explanation . I have seen all your videos .You are doing great job

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

    Thanks for the video ayushi.

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

    @Ayushi Sharma won't the space complexity be O(min(n1, n2, n3)) in place of O(n1+n2+n3) if we are not returning the vector

  • @tarunkumar.d8379
    @tarunkumar.d8379 2 ปีที่แล้ว

    While explaining logic you said we need to increment the index of the lowest element, but in code you are only checking 2 arrays, why and how does it work?

  • @mayankdham1609
    @mayankdham1609 3 ปีที่แล้ว

    Nice work. In this way we are able to solve all ques of sheet😃😃

  • @ANUJ-we3su
    @ANUJ-we3su 2 ปีที่แล้ว

    Can u explain what if i becomes out of bound on line 30 we are trying to compare the index ith element of arr1 which ig should throw an error Let us consider this test case (n1=3 n2=4 n3=5 and arr1={3 3 3 } arr2={3 3 4 5} arr3={3 3 5 7 8} )

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

    Good Explanation👌🤞

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

    i didn't got the point of time complexity like there is a while loop inside of while i know it is n1+n2+n3 but in my mind it's o(n^2) can u please explain that please!!

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

      it is because each element is visited only once

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

      @@AyushiSharmaDSA ohhh yuppp now i got the point thanks a lot for explaining

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

    good explanation

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

    why the time complexity is not O(n^2) (here we are using the while loop inside the while loop) can you explain this?

    • @tarunkumar.d8379
      @tarunkumar.d8379 2 ปีที่แล้ว

      You are visiting every element only once

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

      @@tarunkumar.d8379 thank you
      😃😃

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

    Great!!✨

  • @ecs185_shaileshbharti3
    @ecs185_shaileshbharti3 3 ปีที่แล้ว

    Hi Dii , Understood the algorithm but in handling the duplicates in else if part ,why are we putting arr1[i] to prev1 while checking arr1[i]

    • @AyushiSharmaDSA
      @AyushiSharmaDSA  3 ปีที่แล้ว

      Hi, this is because when we get common element, we are updating prev. Why are we having prev is so that we do not add the same common element again and again, so if the current element is same as prev element, it's already considered, so go ahead. (That is what we are doing in while loop). Let me know if you understood it now🙂

    • @ecs185_shaileshbharti3
      @ecs185_shaileshbharti3 3 ปีที่แล้ว

      @@AyushiSharmaDSA Yaa this I already understood ,What i meant was "we are updating i++ bcz arr1[i]

    • @ecs185_shaileshbharti3
      @ecs185_shaileshbharti3 3 ปีที่แล้ว

      @@AyushiSharmaDSA I will dry run the program few more times ,i guess i am missing or mismatching something 😅

  • @siddhantyadav4531
    @siddhantyadav4531 3 ปีที่แล้ว

    Great work 👍👍👍👍

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

    Big fan mam

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

    thanks.

  • @EternalCoders
    @EternalCoders 3 ปีที่แล้ว

    Maximum xorr value vala program bata do

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

    Mam plz Python code bhi dijiye bhut se log Python se dsa krte hai to mam pzz add Python code also

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

    Nhi samjha kuch prev wala concept

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

    😡😡