BackmediumHash Maps hash-maps medium

Unique Vehicle Intersections Solution

Problem Statement

Given an array of vehicle identifiers and timestamps, implement a function to count the number of unique vehicles approaching each intersection within a given time frame.

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

Explanation: The function returns a dictionary with intersection identifiers as keys and counts of unique vehicles as values.

Constraints

  • The input array is sorted by timestamp.
  • The vehicle identifiers and timestamps are non-negative integers.
  • The time frame is assumed to be the entire duration of the input array.
  • The function should return a dictionary with intersection identifiers as keys and counts of unique vehicles as values.
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