Group Profiles Into Households by Shared Devices

Last updated: November 29, 2026

Quick Overview

Given sign-in records as (profile_id, device_id) pairs, treat two profiles as the same household if they used a common device, directly or through a chain of shared devices, and return the households as sorted lists of profiles, largest first.

Netflix
Coding & Algorithms
Software Engineer
Netflix
November 29, 2026
Software Engineer
Online Assessment
Coding & Algorithms
Easy

0

0

0 solved


Given sign-in records as (profile_id, device_id) pairs, treat two profiles as the same household if they used a common device, directly or through a chain of shared devices, and return the households as sorted lists of profiles, largest first.

Understanding which profiles share a household matters at Netflix for features like extra member and for keeping recommendations from blending across homes. This union find question checks that the candidate maps a real data problem onto connected components and implements union by size with path compression without bugs.

What the Interviewer Expects
  • Recognize connected components over a bipartite profile-device relation
  • Use union find with path compression and union by size
  • Avoid unioning against every profile on a device by remembering one representative
  • Produce deterministic output ordering
  • Compare briefly to BFS on an explicit graph
Key Topics to Cover
union find
connected components
hash maps
graph modeling
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you prevent a shared hotel TV from merging hundreds of unrelated households?
  • How would you support removing a sign-in record later?
  • How would you run this over billions of records in a batch job?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Input is a list of (profile, device) pairs, possibly with repeats. Profiles connected through any chain of shared devices are one group. Output every group (including singletons) as a sorted list, gro...

High-Level Design

Keep a disjoint set over profiles. For each device remember the first profile seen on it; every later profile on that device is unioned with that representative. Because union is transitive, one union...


Submit Your Answer
Markdown supported