Longest Common Contiguous User Actions
Updated
Problem statement
Two ordered arrays, first and second, contain actions performed by two users. Return their longest common contiguous block as an array of action strings. Consecutive actions in the result must occupy adjacent positions in each original array; you may not skip actions inside a block.
For this exercise, assume actions are complete, nonempty, case-sensitive strings. Compare whole tokens, allow repeated tokens and do not change either input.
For this exercise, assume equal-length answers choose the block that starts earliest in first. Return an empty array when there is no nonempty common block, including when either input array is empty.
Function
longestCommonActions(first: String[], second: String[]) → String[]Examples
Example 1
first = ["hi","bye","hello","leetcode","start","end"]second = ["hi","stop","leetcode","start","end","bye"]return = ["leetcode","start","end"]The answer is leetcode, start, end: these three actions occupy adjacent positions in both arrays. Adding hi would require skipping actions and is not a contiguous block.
Example 2
first = ["a","b"]second = ["b","a"]return = ["a"]Both one-action blocks have maximum length. Choose a because its block starts earlier in the first array.
Constraints
- For this exercise, assume
0 <= first.length, second.length <= 150. - For this exercise, assume every token has
1to30printable ASCII characters with codes33through126. - Inputs preserve action order; repeated values are valid and no normalization is applied.
More Wayfair interview questions
- Container With Most WaterPHONE SCREEN · Seen Sep 2026
- Assign Distinct Letter Values to Minimize XORPHONE SCREEN · Seen Sep 2026
- First Three Badge Times per UserPHONE SCREEN · Seen Apr 2022
- Time of Maximum Mall OccupancyPHONE SCREEN · Seen Apr 2022
- Count a Person’s Distinct FriendsPHONE SCREEN · Seen Mar 2022
- Word Path Moving Only Right or DownPHONE SCREEN · Seen Mar 2022
- Tree Nodes with Zero or One ParentPHONE SCREEN · Seen Sep 2021
- UCB1 Multi-Armed Bandit TraceONSITE INTERVIEW · Seen Sep 2026
- Moving Cost by Volume and CategoryONSITE INTERVIEW · Seen Sep 2026
- DFS Subsequences of a String (For MLE)OA · Seen Sep 2024
Similar questions at other companies
- Query Words Within K PositionsPalantir · PHONE SCREENPalantir interview questions
- Word BreakAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Most Relevant Text SpanHebbia · PHONE SCREEN
- Word BreakBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Longest Common URL History RunDatadog · PHONE SCREENDatadog interview questions
- Word BreakMoveworks · ONSITE INTERVIEWMoveworks interview questions
- Recursively Expanded Shell Command CountsZipRecruiter · OAZipRecruiter interview questions
- Rank Word-Translation Hints from Sentence TranslationsDuolingo · PHONE SCREEN · ONSITE INTERVIEWDuolingo interview questions
- Linked Merchants Within Two HopsStripe · PHONE SCREENStripe interview questions
- Largest Number Below N from Reusable DigitsByteDance · PHONE SCREENByteDance interview questions