A trending page shows the same set of topics yesterday (before) and today (after), each as a list of distinct topic names from first place to last. To measure how much the ranking changed, count the pairs of topics that the two lists put in opposite order.
Write disagreement(before, after) that returns that count. Both lists contain exactly the same names. Aim for O(n log n).
Input: before = ["css","js","html"], after = ["js","css","html"] Output: 1
Only the pair css/js swapped places.
Input: before = ["a","b","c","d"], after = ["d","c","b","a"] Output: 6
A full reversal flips all 6 pairs.
0 <= before.length <= 100000after is a reordering of before.Run 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 #196 Ranking Disagreement. 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.