A dashboard places cards in two columns. Card i is heights[i] pixels tall, and every card must go into exactly one of the two columns. The page looks best when the two columns end at nearly the same height.
Write balanceColumns(heights) that returns the smallest possible difference between the total heights of the two columns.
Input: heights = [3,9,4,2,7] Output: 1
3 + 9 = 12 in one column and 4 + 2 + 7 = 13 in the other.
Input: heights = [10] Output: 10
One card means one column is empty.
1 <= heights.length <= 1001 <= heights[i] <= 500Run 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 #513 Balance Two Dashboard Columns. 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.