A live-stream dashboard records each viewer's session as [start, end] in seconds; the viewer is watching at every second from start to end, both included. Analysts then ask about specific moments, listed in times.
Write viewersAt(sessions, times) that returns an array where item i is the number of sessions watching at second times[i]. Answer in the same order as times.
Input: sessions = [[1,6],[3,7],[9,12],[4,13]], times = [2,3,7,11] Output: [1,2,2,2]
At second 7, the sessions [3, 7] and [4, 13] are watching.
Input: sessions = [[1,10],[3,3]], times = [3,3,2] Output: [2,2,1]
[3, 3] only watches at second 3.
0 <= sessions.length, times.length <= 500000 <= start <= end <= 10^90 <= times[i] <= 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 #589 Viewers at Each Query Time. 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.