An activity feed keeps event times in times, sorted from oldest to newest. Several events can share the same time. A new event with time time arrives, and it must be shown before any events that have the same time.
Write insertIndex(times, time) that returns the index where the new event should be inserted: the first index whose time is greater than or equal to time. If every time is smaller, return times.length.
The feed can be long, so aim for O(log n).
Input: times = [100,200,200,300], time = 200 Output: 1
The first 200 is at index 1, so the new event goes there, before both copies.
Input: times = [100,200,300], time = 250 Output: 2
300 at index 2 is the first time that is not smaller than 250.
0 <= times.length <= 100000times is sorted ascending.0 <= times[i], time <= 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 #155 Slot for a New Timestamp. 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.