Skip to the code
cf.
+25 XP

#7 Three Widgets Fill the Row

medium

A dashboard builder lets you place exactly three widgets side by side in a row that is rowWidth pixels wide. The available widgets have the widths in widths.

Write fillingTriples(widths, rowWidth) that returns every choice of three different widgets whose widths add up to exactly rowWidth, as index triples [i, j, k] with i < j < k.

Return the triples sorted: by i, then by j, then by k. Return [] if there are none.

Example 1

Input: widths = [100,150,250,50,200], rowWidth = 500
Output: [[0,1,2],[2,3,4]]

100 + 150 + 250 and 250 + 50 + 200 both make 500; no other triple does.

Example 2

Input: widths = [10,10,10,10], rowWidth = 30
Output: [[0,1,2],[0,1,3],[0,2,3],[1,2,3]]

Any three of the four widgets fit.

Constraints

  • 0 <= widths.length <= 100
  • 1 <= widths[i] <= 2000
  • 1 <= rowWidth <= 6000
Saved in this browser

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).