Find common elements in three sorted arrays | GeeksforGeeks

Поділитися
Вставка
  • Опубліковано 23 кві 2017
  • GeeksforGeeks Article: www.geeksforgeeks.org/find-com...
    Practice Problem: practice.geeksforgeeks.org/pro...
    This video is contributed by Aditi Bainss
    Please Like, Comment, Share the Video among your friends.
    Also, Subscribe if you haven't already! :)

КОМЕНТАРІ • 28

  • @salma_techie
    @salma_techie 4 роки тому +1

    good one there....

  • @bhushandhodi1915
    @bhushandhodi1915 7 років тому +12

    Audio is too low...

    • @nands4410
      @nands4410 7 років тому +1

      Bhushan Dhodi Yes and suddenly it increases and decreases

    • @nands4410
      @nands4410 6 років тому +1

      I don't remember when I comment that

  • @K_EC_piyushkumarsingh
    @K_EC_piyushkumarsingh 2 роки тому +10

    Possibly your code doesn't work correctly for multiple test-cases (TCs).
    The first test case where your code failed:
    Input:
    3 3 3
    3 3 3
    3 3 3
    3 3 3
    Its Correct output is:
    3
    And Your Code's output is:
    3 3 3

    • @prajwalurkude007
      @prajwalurkude007 2 роки тому

      Actual logically the solution is correct, it is printing all the common elements from each arrays.

    • @K_EC_piyushkumarsingh
      @K_EC_piyushkumarsingh 2 роки тому

      @@prajwalurkude007 but we have to handle all the cases

    • @deepanshugrover2672
      @deepanshugrover2672 2 роки тому

      @@K_EC_piyushkumarsingh Use TreeSet to store ans and at the end use list.addAll(treeset) to put non duplicates in list

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

      @@deepanshugrover2672 we don't have to use any additional data structure for maintaining dublicates it's mentioned

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

      if u r using ArrayList to store ans then before adding the element check if it exists in the list

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

    🙂
    class Solution {
    ArrayList commonElements(int A[], int B[], int C[], int n1, int n2, int n3) {
    ArrayList result = new ArrayList();
    int i = 0, j = 0, k = 0;
    while (i < n1 && j < n2 && k < n3) {
    if (A[i] == B[j] && B[j] == C[k]) {
    // Check if the current element is not a duplicate
    if (i == 0 || A[i] != A[i - 1]) {
    result.add(A[i]);
    }
    i++;
    j++;
    k++;
    } else if (A[i]

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

    duplicates are not managed I think

  • @Cloud-Radio
    @Cloud-Radio 2 роки тому

    def findCommonelements(arr1,arr2,arr3):
    for i in arr3:
    if i in arr2 and arr1:
    print(i)

    • @user-gq1ij
      @user-gq1ij Рік тому +1

      And the Time complexity becomes
      N3 * (N1 + N2)

  • @akarshmittal9601
    @akarshmittal9601 4 роки тому +1

    How time complexity is O( n1+ n2+ n3 )?

  • @bharatlakhera9727
    @bharatlakhera9727 2 роки тому +2

    Bhai thoda zoor se bola kro

  • @anjandey6089
    @anjandey6089 3 роки тому +2

    poor explaination

  • @manikanth.8507
    @manikanth.8507 3 роки тому +4

    Bhaut tatti explanation diye HO GFK