A pin board places cards of different heights into columns columns. Cards are placed in order, each at the bottom of the column that is currently shortest. If several columns are equally short, the leftmost one (smallest index) is used.
Write pinColumns(heights, columns) that returns, for each card, the index of the column it goes into. There is no gap between cards.
Input: heights = [200,120,160,80,140], columns = 3 Output: [0,1,2,1,2]
The first three cards fill the empty columns. Then column 1 (120) is shortest, then column 2 (160 vs 200 and 200).
Input: heights = [10,10,10,10], columns = 2 Output: [0,1,0,1]
Ties always go to the leftmost column.
0 <= heights.length <= 10^4, 1 <= heights[i] <= 10^41 <= columns <= 20Run 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 #729 Pin Board 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.