FastPrepLongest Common URL History Run
Problems/Longest Common URL History Run

Longest Common URL History Run

Datadog logoDatadog● MediumFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: The firsthand report provides this contiguous-URL-history task, the no-repeat condition and all four displayed examples. This exercise specifies exact string comparison, tie order, empty behavior, callable and bounds. The core task matches the report at about 95%.

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 0 and 200 URLs.
  • Every URL contains between 1 and 200 printable ASCII characters.
  • Each history contains no repeated URL.
  • The total number of characters across both histories is at most 5000.

More Datadog problems

  • Query Log MatchPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Delete a Filesystem TreePHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
  • Grouped-Query Attention Forward PassPHONE SCREEN · Seen Jun 2026
All Datadog interview questionsSee Datadog hiring insights
Saved
public String[] longestCommonUrlRun(String[] first, String[] second) {
    // Write your code here.
}
Checking account…