FastPrepObjects Seen on Both Days by Multiple Clients

Objects Seen on Both Days by Multiple Clients

Google logoGoogle● MediumINTERNPHONE SCREEN
Learn

Problem statement

You are given two daily log files, represented by dayOneLogs and dayTwoLogs. Each row has exactly three strings: [timestamp, objectId, clientId].

Return every object ID that:

  • appears in at least one record on each day, and
  • is associated with at least two distinct client IDs across the two days combined.

Return qualifying object IDs in lexicographically increasing order. Duplicate log rows do not change the result.

Function

findRepeatedObjects(dayOneLogs: String[][], dayTwoLogs: String[][]) → String[]

Examples

Example 1

dayOneLogs = [["09:00","objA","c1"],["09:10","objB","c2"],["09:20","objA","c1"]]dayTwoLogs = [["10:00","objA","c3"],["10:10","objB","c2"],["10:20","objC","c4"]]return = ["objA"]

objA appears on both days and is associated with clients c1 and c3. objB has only one distinct client, and objC appears on only one day.

Example 2

dayOneLogs = [["1","x","a"],["2","y","b"],["3","y","c"]]dayTwoLogs = [["4","y","b"],["5","x","a"],["6","x","d"]]return = ["x","y"]

Both objects appear on both days and each has at least two distinct clients across the combined records.

Example 3

dayOneLogs = []dayTwoLogs = [["1","x","a"]]return = []

No object can appear on both days when the first file is empty.

Constraints

  • 0 <= dayOneLogs.length, dayTwoLogs.length <= 200000.
  • Every row contains exactly three non-null strings.
  • Every object ID and client ID is non-empty.
  • The combined number of characters in each input is at most 2 * 10^6.

More Google problems

See Google hiring insights
public String[] findRepeatedObjects(String[][] dayOneLogs, String[][] dayTwoLogs) {
    // Write your code here.
}
dayOneLogs[["09:00","objA","c1"],["09:10","objB","c2"],["09:20","objA","c1"]]
dayTwoLogs[["10:00","objA","c3"],["10:10","objB","c2"],["10:20","objC","c4"]]
expected["objA"]
Checking account…