A palette editor flags duplicate swatches. colors lists the swatch colors, possibly with repeats.
Write duplicatePairs(colors) that returns how many pairs of positions i < j have colors[i] === colors[j].
Input: colors = ["red","blue","red","red"] Output: 3
The three red swatches make C(3, 2) = 3 pairs.
Input: colors = ["a","b"] Output: 0
No color appears twice.
0 <= colors.length <= 10^5Run 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 #651 Matching Swatch Pairs. 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.