Google questions

Objects Shared by Two Logs

GoogleEasy

Each log is a list of entries [timestamp, obj_id, client_id]: at time timestamp, client client_id used object obj_id. Both ids are strings, and the logs are not sorted.

Part 1: Objects used by two clients in both logs

You are given two access logs, log_a and log_b. Every entry is [timestamp, obj_id, client_id], meaning client client_id used object obj_id at time timestamp. Both ids are strings, and neither log is sorted.

Return every obj_id that appears in both logs and was used by at least two different clients when the two logs are combined. Return each such id once, in ascending string order.

A client counts once no matter how many times it uses an object, and its uses in either log count: an object touched by c1 in log_a and by c2 in log_b has two clients. Timestamps do not affect the answer.

  1. Example 1
    log_a
    [[1,"X","c1"],[2,"X","c2"],[3,"Y","c1"]]
    log_b
    [[4,"X","c1"],[5,"Z","c2"]]
    Output
    ["X"]

    Why: X appears in both logs and its clients across the two logs are c1 and c2, so it qualifies. Y appears only in log_a and Z only in log_b, so neither qualifies.

  2. Example 2
    log_a
    [[1,"p","c1"],[2,"q","c1"],[3,"r","c2"],[4,"r","c2"]]
    log_b
    [[1,"p","c1"],[2,"q","c2"],[3,"r","c2"],[4,"s","c9"]]
    Output
    ["q"]

    Why: p is used only by c1 and r only by c2, so each has a single client and neither counts. q is used by c1 in log_a and by c2 in log_b, giving it two clients, so it counts.

Constraints

  • 0 <= len(log_a), len(log_b) <= 10^5
  • 1 <= len(obj_id), len(client_id) <= 20
  • 0 <= timestamp <= 10^9
  • Each entry is [timestamp, obj_id, client_id]
Import your own questions
Paste a question you were asked and get a full problem: statement, tests and a checked solution.
Import a question