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.
- Prepare
- Algorithms
- Greedy
- Beautiful Pairs
- Discussions
Beautiful Pairs
Beautiful Pairs
Sort by
recency
|
274 Discussions
|
Please Login in order to post a comment
Java Solution
C++ (more at https://github.com/IhorVodko/Hackerrank_solutions/tree/master , feel free to give a star :) )
I do not appreciate the "gotcha" descriptions. It is NOT stated explicitly that you should change one element in B to ANOTHER VALUE, therefore if the aim is to maximize the number of disjoint pairs I, and I hope any sane person, would read this requirement as changing one element in B unless the number of disjoint pairs is already maximal.
I don't see how the editorial or solutions people are presenting account for the disjoint property?
In sample 1 we have
which, if we sort, we can see;
You can see sets of 5, 6, 8, and 11. This is 4 sets. Is we allow non-disjoint sets, we have 2 copies of the set of 5. So, with disjoint pairs we have 4 right now, non-disjoint we have 5. If we make 1 change we can change a 5 to a 3, or the 10 to a 3 to add 1 more set. If we change the 10, and we only count disjoint pairs we now have 5, but if we count the non-disjoint pairs of 5, we have 6 now.
The answer shown is 6. So, the problem instructions/explanation seem in error?