Longest Common Contiguous String Sequence
Updated
Problem statement
Given string arrays first and second, return their longest common contiguous sequence of complete elements. The returned values must appear next to each other, in the same order, in both arrays.
Treat each string as one opaque value. Compare whole strings exactly, including case and spaces. Do not concatenate values or compare characters inside them. Values are unique within each input array; the same value may occur once in each array.
For this exercise, assume ties choose the sequence whose start index in first is smallest. If either input is empty or there is no common element, return an empty array.
Function
longestCommonSequence(first: String[], second: String[]) → String[]Examples
Example 1
first = ["home","search","item","cart"]second = ["login","search","item","checkout"]return = ["search","item"]Search and item are consecutive in both arrays, at indices 1 and 2. Neither neighboring value extends the match, so this two-element sequence is longest.
Example 2
first = ["x","a","b","y","c","d"]second = ["a","b","z","c","d"]return = ["a","b"]Both a,b and c,d have length two. Their starts in first are 1 and 4, so the earlier sequence a,b wins.
Constraints
- For this exercise, assume each input array has 0 to 1000 elements.
- Each string contains 1 to 40 printable ASCII characters, with codes 32 through 126.
- No value repeats within first, and no value repeats within second.
More Intuit Online Assessment questions
- Employee Promotion OpportunitiesOA · Seen Oct 2026
- Next Pascal Row CoefficientOA · Seen Oct 2026
- Parse Router LogsOA · Seen Oct 2026
- Longest Repeated Letter Block with Adjacent SwapsOA · Seen Oct 2026
- Maximum Square-Free DivisorOA · Seen Oct 2026
- Two Tribes from Taller-Person CountsOA · Seen Oct 2026
- Shortest Path from an Encoded GraphOA · Seen Sep 2026
- Oldest and Youngest EmployeesOA · Seen Sep 2026
- Pressure-Isolation Shutdown OrderOA · Seen Sep 2026
- Submask Sum QueriesOA · Seen Sep 2026
Similar questions at other companies
- Maximum Escape Game ScoreMicrosoft · OAMicrosoft interview questions
- Maximum Points by Deleting ElementsIBM · OAIBM interview questions
- Maximum Points by Deleting ElementsWalmart · OAWalmart interview questions
- Bitwise XOR SubsequencesJP Morgan Chase · OAJP Morgan Chase interview questions
- Bitwise XOR SubsequencesGoldman Sachs · OAGoldman Sachs interview questions
- Get Maximum ScoreAtlassian · OAAtlassian interview questions
- Optimize Discount Selection Under a Point BudgetPalantir · OAPalantir interview questions
- Word BreakAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Maximum Subarray Sum with Equal EndpointsGoogle · ONSITE INTERVIEWGoogle interview questions
- Word BreakMoveworks · ONSITE INTERVIEWMoveworks interview questions