Longest Common URL History Run
Problem statement
Two chronological browsing histories contain URL strings. Return the longest contiguous sequence of URLs appearing in both histories in the same order. A sequence must occupy consecutive positions in each history; it is not an arbitrary subsequence.
Compare whole URL strings exactly and case-sensitively, without parsing or normalizing them. Treat them as opaque identifiers. If several longest sequences exist, choose the one starting earliest in first; if still tied, choose the earliest start in second. If no URL is shared, return an empty array. Do not change either input.
Function
longestCommonUrlRun(first: String[], second: String[]) → String[]Examples
Example 1
first = ["/start.html","/pink.php","/register.asp","/orange.html","/red.html"]second = ["/start.html","/green.html","/blue.html","/pink.php","/register.asp","/orange.html"]return = ["/pink.php","/register.asp","/orange.html"]The three URLs appear at positions 1..3 in the first history and 3..5 in the second. The shared /start.html cannot extend that run because the intervening URLs differ.
Example 2
first = ["/red.html","/green.html","/blue.html","/pink.php","/register.asp"]second = ["/start.html","/green.html","/blue.html","/pink.php","/register.asp","/orange.html"]return = ["/green.html","/blue.html","/pink.php","/register.asp"]The run starts at position 1 in each history and has four consecutive URLs. It cannot extend left because /red.html differs from /start.html, or right because the first history ends.
Example 3
first = ["/start.html","/pink.php","/register.asp","/orange.html","/red.html"]second = ["/blue.html","/logout.php"]return = []The histories have no URL in common, so no nonempty shared run exists.
Example 4
first = ["/red.html","/green.html","/blue.html","/pink.php","/register.asp"]second = ["/blue.html","/logout.php"]return = ["/blue.html"]The URL /blue.html is shared. The following URLs are /pink.php and /logout.php, so the run has length one.
Constraints
- Each history contains between
0and200URLs. - Every URL contains between
1and200printable ASCII characters. - Each history contains no repeated URL.
- The total number of characters across both histories is at most
5000.