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.
count by B pairs where A<=B (array length should be C, init with zeros) - sum of this array is a total count of quadruples
accumulate above count for each B
count by B how times unique xor's happaned for pairs AB (so we have a frequency matrix, where row is B and column is xor)
acummulate above matrix by row (by B)
iterate over all pairs CD where C<D and look at above matrix for C^D and subtract the found count from total count at step 1. This difference will be the final result.
Main points:
constrain that we use only pairs where x<=y filters pairs so count of x and y is unique (if we had 12, no need for 21)
use accumulation containers to not recompute frequencies again and again
x^y = 0 when x == y, in our case when A^B == C ^ D
Beautiful Quadruples
You are viewing a single comment's thread. Return to all comments →
C++(more at https://github.com/IhorVodko/Hackerrank_solutions , feel free to give a star:) )
Main points: