A layout tool places two cards side by side in a row that is target pixels wide. The card widths are in widths.
Write countFillingPairs(widths, target) that returns how many pairs of indexes i < j have widths[i] + widths[j] === target. Cards with the same width are still different cards.
Input: widths = [3,5,2,5,3], target = 8 Output: 4
Each of the two 3s pairs with each of the two 5s: 4 pairs.
Input: widths = [4,4,4,4], target = 8 Output: 6
Any two of the four 4s work, and there are 6 ways to pick two.
0 <= widths.length <= 10^5-10^9 <= widths[i], target <= 10^9Run 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 #29 Count Pairs That Fill the Row. 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.