Two user sessions are recorded as arrays of event ids, a and b. An analyst wants the longest run of events that appears in both sessions back to back, with nothing in between (a common contiguous subarray).
Write longestSharedRun(a, b) that returns its length, or 0 if the sessions share no event.
Input: a = [4,7,1,8,2,5], b = [9,1,8,2,6] Output: 3
[1, 8, 2] appears in both, back to back.
Input: a = [1,2], b = [3,4] Output: 0
No event is shared.
1 <= a.length, b.length <= 10000 <= a[i], b[i] <= 100Run 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 #567 Longest Shared Run of Events. 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.