PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/Snapchat

Find max node-value range across components

Last updated: Mar 29, 2026

Quick Overview

This question evaluates understanding of undirected graph connectivity and component-wise aggregation, specifically the ability to identify connected components and compute min/max node labels to derive component ranges.

  • medium
  • Snapchat
  • Coding & Algorithms
  • Software Engineer

Find max node-value range across components

Company: Snapchat

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

## Problem You are given an **undirected graph** with: - `n`: number of nodes (assume nodes are labeled `1..n`) - `from[]`: list of edge start nodes - `to[]`: list of edge end nodes Each pair `(from[i], to[i])` represents an undirected edge. For each **connected component**, compute the difference: \[ \text{range(component)} = \max(\text{node labels in component}) - \min(\text{node labels in component}) \] Return the **maximum range** across all connected components. (An isolated node has range 0.) ## Example Input: - `n = 4` - `from = [1, 2, 3]` - `to = [2, 3, 1]` The component `{1,2,3}` has range `3 - 1 = 2`, node `4` alone has range `0`, so return `2`. ## Requirements - Provide an efficient solution and state the **time and space complexity**. - Assume `from.length == to.length` and the graph may contain multiple components.

Quick Answer: This question evaluates understanding of undirected graph connectivity and component-wise aggregation, specifically the ability to identify connected components and compute min/max node labels to derive component ranges.

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 10, 2026, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
2
0
Loading...

Problem

You are given an undirected graph with:

  • n : number of nodes (assume nodes are labeled 1..n )
  • from[] : list of edge start nodes
  • to[] : list of edge end nodes

Each pair (from[i], to[i]) represents an undirected edge.

For each connected component, compute the difference:

range(component)=max⁡(node labels in component)−min⁡(node labels in component)\text{range(component)} = \max(\text{node labels in component}) - \min(\text{node labels in component})range(component)=max(node labels in component)−min(node labels in component)

Return the maximum range across all connected components. (An isolated node has range 0.)

Example

Input:

  • n = 4
  • from = [1, 2, 3]
  • to = [2, 3, 1]

The component {1,2,3} has range 3 - 1 = 2, node 4 alone has range 0, so return 2.

Requirements

  • Provide an efficient solution and state the time and space complexity .
  • Assume from.length == to.length and the graph may contain multiple components.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

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