Question bank › Two Pointers
Dsa Two Pointers Medium

Count Distinct Elements in Range

You are given an array of integers and a query defining a range. Your goal is to find the number of distinct integers within that range, both inclusive. Input format: - A single line containing N (1 ≤ N ≤ 100000), the number of elements in the array. - A second line containing N integers, each representing an element of the array. - A third line containing two integers L and R (0 ≤ L < R < N), defining the range of interest. Output format: - A single integer indicating the number of distinct integers in the specified range. Example: Input: 8 1 2 2 3 3 4 5 1 1 5 Output: 4

Key concepts

two_pointersarrayshashing

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.