A chart shows tooltips that stretch horizontally; tooltip i covers the x positions from spans[i][0] to spans[i][1], both ends included. One click at position x pins every tooltip with start <= x <= end.
Write fewestClicks(spans) that returns the smallest number of clicks that pin every tooltip.
Input: spans = [[11,15],[3,9],[2,5],[8,13]] Output: 2
Click at 5 (pins [3, 9] and [2, 5]) and at 13 (pins [11, 15] and [8, 13]).
Input: spans = [[1,2],[3,4],[5,6]] Output: 3
No two tooltips share a position.
0 <= spans.length <= 100000-2^31 <= start <= end <= 2^31 - 1Run 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 #579 Fewest Clicks to Pin Every Tooltip. 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.