Solve pair-counting and account-merging problems
Company: TikTok
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Overview: This question evaluates proficiency in algorithmic problem-solving for pair counting and entity consolidation, focusing on efficient array processing, threshold-based counting, and merging records by shared identifiers, and it falls under the Coding & Algorithms domain.
Count Products Meeting a Threshold
Constraints
- len(A), len(B) can be up to 1e5
- Values are non-negative
Examples
Input: ([2, 4, 0], [1, 3, 5], 10)
Expected Output: [1, 2, 0]
Input: ([0, 1], [0, 2], 0)
Expected Output: [2, 2]
Hints
- Sort B and binary-search the smallest b that works for each a.
Merge Accounts by Shared Identifiers
Constraints
- Total identifiers <= 1e5
Examples
Input: ([['John', 'a@mail', 'b@mail'], ['John', 'b@mail', 'c@mail'], ['Mary', 'z@mail']],)
Expected Output: [['John', 'a@mail', 'b@mail', 'c@mail'], ['Mary', 'z@mail']]
Input: ([['B', 'x'], ['A', 'x', 'y'], ['C', 'q']],)
Expected Output: [['A', 'x', 'y'], ['C', 'q']]
Hints
- Use union-find on identifiers.
- Sort the final identifiers to make output deterministic.