An analytics dashboard stores the times of all click events in times, sorted ascending. Several clicks can share a time. The user drags out several time windows on a chart, and each window [from, to] should show how many clicks happened from from to to, including both ends.
Write countInWindows(times, windows) that returns an array with one count per window, in the same order as windows.
There can be many windows, so answer each one faster than a scan over times.
Input: times = [1,3,3,5,8,13], windows = [[2,5],[6,7]] Output: [3,0]
Clicks at 3, 3, and 5 fall in [2, 5]. None fall in [6, 7].
Input: times = [10,20,30], windows = [[10,30],[0,10],[30,99]] Output: [3,1,1]
Both ends count, so [10, 30] holds all three clicks.
0 <= times.length <= 100000times is sorted ascending.1 <= windows.length <= 100000from <= to in every window.Run 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 #157 Events in Time Windows. 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.