Beautiful Pairs

  • + 0 comments

    can anyone help me out with this C# code its failing fro one testcase:

    public static int beautifulPairs(List A, List B) { HashSet setB = new HashSet(B); int bPairs = 0;

    foreach (int i in A)
    {
        if (setB.Contains(i))
        {
            bPairs++;
            setB.Remove(i); // Ensures pairwise disjoint condition
        }
    }
    
    // If all elements are matched, changing any element reduces the count
    if (bPairs == A.Count)
    {
        return bPairs - 1; // Change one element in B to break a pair
    }
    else
    {
        return bPairs + 1; // We can increase the count by changing one element in B
    }
    

    }