PracHub
QuestionsPremiumLearningGuidesInterview PrepNEWCoaches
|Home/Coding & Algorithms/Google

Group movies via graph traversal

Last updated: Mar 29, 2026

Quick Overview

This question evaluates graph traversal and connectivity skills, specifically competence with BFS, DFS (iterative and recursive), complexity analysis, and Union-Find for identifying connected components in an undirected graph.

  • Medium
  • Google
  • Coding & Algorithms
  • Software Engineer

Group movies via graph traversal

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Onsite

You are given n movies labeled 0..n-1 and a list of undirected pairs (a, b) meaning movies a and b are similar. Group all movies into categories where each category is a maximal set of movies connected via similarity links (i.e., connected components). Return the categories as lists of movie IDs, each list sorted, and the collection sorted by the smallest ID in each category. Implement solutions using both BFS and DFS, explain their time/space complexity, and compare iterative vs. recursive DFS. Then discuss an alternative Union-Find approach and when it would be preferable. Dry-run on n=8 with pairs: (0, 1),(1, 2),(3, 4),(5, 6),(6, 7).

Quick Answer: This question evaluates graph traversal and connectivity skills, specifically competence with BFS, DFS (iterative and recursive), complexity analysis, and Union-Find for identifying connected components in an undirected graph.

Related Interview Questions

  • Solve Flower Placement and Directory Deletion - Google (medium)
  • Compute Turnstile Crossing Times - Google (hard)
  • Simulate In-Place Cellular State Updates - Google (hard)
  • Determine Whether a Word Exists in a Graph - Google (medium)
  • Implement Checksums and Feature Rollout Evaluation - Google (medium)
Google logo
Google
Sep 6, 2025, 12:00 AM
Software Engineer
Onsite
Coding & Algorithms
3
0

You are given n movies labeled 0..n-1 and a list of undirected pairs (a, b) meaning movies a and b are similar. Group all movies into categories where each category is a maximal set of movies connected via similarity links (i.e., connected components). Return the categories as lists of movie IDs, each list sorted, and the collection sorted by the smallest ID in each category. Implement solutions using both BFS and DFS, explain their time/space complexity, and compare iterative vs. recursive DFS. Then discuss an alternative Union-Find approach and when it would be preferable. Dry-run on n=8 with pairs: (0, 1),(1, 2),(3, 4),(5, 6),(6, 7).

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Google•More Software Engineer•Google Software Engineer•Google Coding & Algorithms•Software 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.