We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
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
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Beautiful Pairs
You are viewing a single comment's thread. Return to all 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;
}