Beautiful Pairs

  • + 0 comments

    The Larger Test Cases for this question seems to be incorrect or at the very least, not all scenarios are considered. Here's a basic outline of some of the accepted answers following this logic: 1. Add to a Hasmap 2. Go through the list and reduce the hash value until one of the values is exhaused (add to count on each iteration where you find a value) 3. if(cnt != A.size()) return cnt++; else reutrn cnt--;

    Alternatively, You can remove the used Integers from the List instead of using a hash map. But in principle, the logic remains the same.

    The issue is, using this method, it considers non-disjoint values as well as disjoint values. Take this case for example: 5

    1 2 3 3 3

    1 2 3 1 1

    Now, if you were to exhaust the list one by one and switch one of the 1s to 3, you would end up with 4. Which is the correct number of Beautiful Numbers, but not the number of pairwise disjoint beautiful numbers. The correct number of pairwise disjoint numbers attainable in this scenario is 1: (2, 2) at index [1][1]. Since, no matter how we switch one Exactly 1 element in B, we cannot switch at least 1 in set B and have more than one disjoint beautiful pair. If I have misunderstood any part of the text, feel free to reply to this comment.