A chat app shows messages from a local cache and new ones from the server. Both lists hold timestamps sorted ascending: cached and fresh.
Write mergeTimelines(cached, fresh) that returns one array with every timestamp from both lists, sorted ascending. Keep duplicates. Do it in one pass, the way merge sort's merge step does, rather than sorting again.
Input: cached = [1,4,9], fresh = [2,3,10] Output: [1,2,3,4,9,10]
Take the smaller front value each time.
Input: cached = [5,5], fresh = [5] Output: [5,5,5]
Duplicates are kept.
0 <= cached.length, fresh.length <= 1000000 <= timestamps <= 10^12Run 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 #191 Merge Two Sorted Timelines. 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.