BackmediumUncategorized uncategorized medium

Unique Messages in Graph Solution

Problem Statement

Given a list of edges in a graph, where each edge represents a message sent from one node to another, calculate the number of unique messages received by each node. The graph has n nodes, and each message is assigned a unique identifier.

Example 1
Input
[[1, 2, 10], [2, 3, 20], [1, 3, 10]]
Output
{1: 0, 2: 1, 3: 2}

Explanation: Node 1 receives 0 unique messages, node 2 receives 1 unique message, and node 3 receives 2 unique messages.

Constraints

  • 1 <= n <= 100
  • 1 <= number of edges <= 1000
  • 1 <= message id <= 1000
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free