A wall display shows a gallery of up to 100,000 tiles in up to 10,000 narrow columns. Tiles are placed in order at the bottom of the currently shortest column; ties go to the smallest column index. There are no gaps.
Write placeTiles(heights, columns) that returns the column index of each tile. Scanning every column for every tile would be too slow at this size.
Input: heights = [5,3,4,1,2], columns = 2 Output: [0,1,1,0,0]
Column heights go [5, 3], [5, 7], [6, 7], and the last tile also goes to column 0 because 6 is less than 7.
Input: heights = [1,1,1], columns = 5 Output: [0,1,2]
With more columns than tiles, each tile takes the next empty column.
0 <= heights.length <= 10^5, 1 <= heights[i] <= 10^41 <= columns <= 10^4Run 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 #731 Masonry for a Huge Gallery. 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.