A visual-regression tool stores each test run as a bit mask of which checks passed. The difference between two runs is the number of bit positions where they differ.
Write totalDifference(snapshots) that returns the sum of the differences over all pairs of runs i < j. There can be 10,000 runs, so checking every pair is too slow.
Input: snapshots = [4,14,7] Output: 6
4 ^ 14 = 1010, 4 ^ 7 = 0011, and 14 ^ 7 = 1001: 2 differences each, 6 in total.
Input: snapshots = [1,1] Output: 0
Identical runs don't differ.
1 <= snapshots.length <= 10^40 <= snapshots[i] < 2^30Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #680 Total Snapshot Difference. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.