Join Sources with Lagged Destination Timestamps
Updated
Problem statement
You are given two materialized tables. Each row of sourceRows is [source, destination, timestamp]. Each row of destinationRows is [destination, timestamp]. Timestamps are nonnegative integer seconds encoded as decimal strings.
A source row matches a destination row when their destination values are equal and the destination-row timestamp is zero, one, or two seconds after the source-row timestamp. Equivalently, if the timestamps are sourceTime and destinationTime, then 0 <= destinationTime - sourceTime <= 2.
Process destinationRows in input order. For each destination row, append the source of every matching source row in sourceRows input order. Preserve duplicate row occurrences. Rows with no match append nothing. Return the resulting list of source strings.
Function
matchLaggedSources(sourceRows: String[][], destinationRows: String[][]) → String[]Examples
Example 1
sourceRows = [["A","X","10"],["B","X","12"],["C","Y","9"]]destinationRows = [["X","12"],["Y","10"]]return = ["A","B","C"]For [X, 12], sources A and B lag by two and zero seconds. For [Y, 10], source C lags by one second.
Example 2
sourceRows = [["first","D","5"],["other","Q","6"],["second","D","6"],["first","D","5"]]destinationRows = [["D","7"],["D","4"],["D","7"]]return = ["first","second","first","first","second","first"]The two identical source rows remain distinct occurrences. The middle destination row has no earlier source within two seconds. Repeating the first destination row repeats its three matches.
Example 3
sourceRows = [["late","A","9"],["edge","A","5"],["wrong","B","6"]]destinationRows = [["A","7"]]return = ["edge"]edge is exactly two seconds earlier. late occurs after the destination row, and wrong has another destination.
Constraints
1 <= sourceRows.length, destinationRows.length <= 20000- Every source row contains exactly three strings, and every destination row contains exactly two strings.
- Source and destination strings are non-empty and contain only letters, digits, underscores, and hyphens.
- Every timestamp is a decimal integer in
[0, 10^9]. - The returned list contains at most
200000source occurrences.
More Pinterest Onsite Interview questions
- Minimum Bus Routes to a DestinationPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Delete and Compact a Forest SubtreePHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Filter Pins by Excluded IDsONSITE INTERVIEW · Seen Oct 2026
- Top-Scoring Items in a Time WindowONSITE INTERVIEW · Seen Oct 2026
- Optimal Account BalancingPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Escape Room LeaderboardPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Policy Violation Set ChecksONSITE INTERVIEW · Seen Sep 2026
- Shortest Sequence of Source SubsequencesONSITE INTERVIEW · Seen Sep 2026
- Insert Addition and Multiplication OperatorsONSITE INTERVIEW · Seen Sep 2026
- Unique Active Pins by Time SegmentONSITE INTERVIEW · Seen Sep 2026
Similar questions at other companies
- Mutual-Friend RecommendationsMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
- Filter, Sort, and Deduplicate Scheduled TasksRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
- Count Zero Request ServersSalesforce · ONSITE INTERVIEWSalesforce interview questions
- Longest Consecutive Login StreakAmazon · ONSITE INTERVIEW
- Group AnagramsMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Top K Frequent ElementsCapgemini · ONSITE INTERVIEWCapgemini interview questions
- Find Duplicate Element PairsGoogle · ONSITE INTERVIEWGoogle interview questions
- Top-K URLs Overall and in the Last 24 HoursOracle · PHONE SCREEN · ONSITE INTERVIEWOracle interview questions
- Read a File from Distributed ChunksHudson River Trading · ONSITE INTERVIEWHudson River Trading interview questions
- Top K Frequent ElementsInfosys · ONSITE INTERVIEWInfosys interview questions