PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/Snapchat

Count Cross-Group Employee Pairs

Last updated: Mar 29, 2026

Quick Overview

This question evaluates understanding of graph connectivity and component aggregation (often involving disjoint-set concepts) along with combinatorial counting to compute cross-group pairs.

  • medium
  • Snapchat
  • Coding & Algorithms
  • Backend Engineer

Count Cross-Group Employee Pairs

Company: Snapchat

Role: Backend Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

You are given `n` employees labeled from `0` to `n - 1` and a list of relationships `relations`, where each pair `[a, b]` means employees `a` and `b` belong to the same group. Group membership is transitive, so if `[0, 1]` and `[0, 2]` are present, then `0`, `1`, and `2` are all in one group. Your task is to count how many unordered pairs of employees `(i, j)` can be formed such that `i` and `j` come from different groups. Example: - `n = 5` - `relations = [[0, 1], [0, 2], [3, 4]]` This creates two groups: `{0, 1, 2}` and `{3, 4}`. The valid cross-group pairs are: - `(0, 3)`, `(0, 4)` - `(1, 3)`, `(1, 4)` - `(2, 3)`, `(2, 4)` So the answer is `6`. Return the total number of valid pairs.

Quick Answer: This question evaluates understanding of graph connectivity and component aggregation (often involving disjoint-set concepts) along with combinatorial counting to compute cross-group pairs.

Related Interview Questions

  • Determine Whether Courses Can Be Completed - Snapchat (medium)
  • Solve Decimal Coin Change - Snapchat (medium)
  • Find Maximum Island Perimeter - Snapchat (medium)
  • Solve Three Algorithmic Tasks - Snapchat (hard)
  • Implement a Timestamped Counter - Snapchat (medium)
Snapchat logo
Snapchat
Jan 28, 2026, 12:00 AM
Backend Engineer
Technical Screen
Coding & Algorithms
3
0

You are given n employees labeled from 0 to n - 1 and a list of relationships relations, where each pair [a, b] means employees a and b belong to the same group. Group membership is transitive, so if [0, 1] and [0, 2] are present, then 0, 1, and 2 are all in one group.

Your task is to count how many unordered pairs of employees (i, j) can be formed such that i and j come from different groups.

Example:

  • n = 5
  • relations = [[0, 1], [0, 2], [3, 4]]

This creates two groups: {0, 1, 2} and {3, 4}. The valid cross-group pairs are:

  • (0, 3) , (0, 4)
  • (1, 3) , (1, 4)
  • (2, 3) , (2, 4)

So the answer is 6.

Return the total number of valid pairs.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Snapchat•More Backend Engineer•Snapchat Backend Engineer•Snapchat Coding & Algorithms•Backend Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.