Skip to main content
Back to problems
Leetcode
Medium
Graphs
Hash Maps
Google
Properties Graph

Given a set of properties and their relationships, build a graph and answer reachability or grouping-style queries over it.

Acceptance 0%
Problem Statement

Properties Graph

You are given a collection of properties and relationships between them. Model the properties as nodes in a graph, where each relationship connects two properties that are related.

Your task is to process the graph and determine the required result for the problem, such as whether properties are connected, how they should be grouped, or what values can be inferred by traversing the relationships.

Because the exact query format is not available from the source metadata, treat this as a graph-processing problem centered on building adjacency information and exploring connectivity efficiently.

Goal

  • Represent relationships between properties as a graph
  • Traverse the graph to compute the requested answer
  • Handle repeated references to the same property efficiently using a mapping structure

Input Format

  • A list of properties or property identifiers
  • A list of relationships/pairs connecting properties
  • Possibly one or more queries over the resulting graph

The exact input shape is not available from the metadata, so the problem should be understood as a graph construction and traversal task.

Output Format

  • Return the result required by the query type, such as a boolean, grouping, count, or derived set of properties

Use a graph traversal or lookup-based approach consistent with the relationships provided.

Constraints

  • Use canonical graph traversal and lookup techniques
  • The underlying graph may contain repeated properties, multiple relationships, or disconnected parts
  • Exact numeric limits are unavailable from the source metadata
Examples
Sample cases returned by the problem API.

Example 1

Input

Properties: [A, B, C, D]
Relationships: [(A, B), (B, C)]
Query: Are A and C connected?

Output

true

Explanation

A is connected to B, and B is connected to C, so A and C belong to the same connected component.

Example 2

Input

Properties: [A, B, C, D]
Relationships: [(A, B), (C, D)]
Query: How many connected groups exist?

Output

2

Explanation

There are two disconnected components: {A, B} and {C, D}.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.