A dashboard builder offers widgets in several widths, listed in widths (the same width can appear more than once, as different widgets). A row looks balanced with exactly four widgets whose widths add up to rowWidth.
Write fourWidgetRows(widths, rowWidth) that returns every distinct group of four width values [a, b, c, d], taken from four different positions, with a + b + c + d === rowWidth. Write each group in ascending order, list the groups in ascending order (compare first values, then second, then third), and list each distinct group once.
Input: widths = [1,0,-1,0,-2,2], rowWidth = 0 Output: [[-2,-1,1,2],[-2,0,0,2],[-1,0,0,1]]
These are the three distinct groups of four that add up to 0.
Input: widths = [3,3,3,3,3], rowWidth = 12 Output: [[3,3,3,3]]
Five widgets of width 3 give only one distinct group.
0 <= widths.length <= 200-10^6 <= widths[i] <= 10^6-10^6 <= rowWidth <= 10^6Run 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 #119 Four Widgets Fill a 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.