Question bank › Intervals
Dsa Intervals Hard

Interval Intersection Count

You are given a list of intervals, and for each interval, you need to determine how many other intervals it intersects with. An interval is considered to intersect with another if they share any part of their ranges. Return a list where each entry corresponds to the count of intersecting intervals for the respective interval in the input list. Input: The first line contains an integer n (1 ≤ n ≤ 10^5) — the number of intervals. The next n lines each contain two integers start and end (1 ≤ start < end ≤ 10^9). Output: Print n integers where the i-th integer is the count of intervals that intersect with the i-th interval. Example: Input: 3 1 3 2 4 5 8 Output: [1, 1, 0]

Key concepts

intervalscountingsweeping

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.