To line up a client log with a server log, an engineer looks for the moment when the two logs are closest in time. client and server are arrays of timestamps in milliseconds, each sorted ascending.
Write closestGap(client, server) that returns the smallest value of Math.abs(client[i] - server[j]) over all pairs. Both arrays have at least one item.
Input: client = [100,350,900], server = [200,340,1500] Output: 10
350 and 340 are 10 ms apart, the closest pair.
Input: client = [5], server = [5] Output: 0
The same moment appears in both logs.
1 <= client.length, server.length <= 1000000 <= timestamps <= 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 #114 Closest Timestamps Across Two Logs. 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.