A dashboard draws rectangular cards that all sit on the same baseline. Card i is [left, right, height]: it covers x from left up to right and rises height units. Cards overlap freely. The designer wants the outline of the whole group seen from the side.
Write outline(cards) that returns the outline as key points [x, h], sorted by x: each key point says that from x onward the outline's height is h, until the next key point. Include a point wherever the height changes, never two points in a row with the same height, and end with a point of height 0 where the last card ends. Return [] for no cards.
Input: cards = [[2,9,10],[3,7,15],[5,12,12],[15,20,10],[19,24,8]] Output: [[2,10],[3,15],[7,12],[12,0],[15,10],[20,8],[24,0]]
For example, from 7 the tallest card is the one of height 12, until it ends at 12.
Input: cards = [[0,2,3],[2,5,3]] Output: [[0,3],[5,0]]
Two touching cards of the same height make one flat stretch.
0 <= cards.length <= 100000 <= left < right <= 10^91 <= height <= 10^9Run 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 #590 Outline of Overlapping Cards. 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.