Question bank › Sliding Window
Dsa Sliding Window Warm-up

Count Subarrays with Distinct Elements

Given an array of integers `arr`, count the number of contiguous subarrays that contain distinct elements. Input Format: - A single line containing space-separated integers representing the array `arr` (1 <= |arr| <= 10^5, 0 <= arr[i] <= 100). Output Format: - Print an integer representing the count of distinct-element subarrays. Example: Input: 1 2 1 3 4 Output: 15 (The distinct subarrays are: [1],[2],[1],[3],[4],[1,2],[2,1],[1,3],[3,4],[1,2,1],[2,1,3],[1,3,4],[1,2,1,3],[2,1,3,4],[1,2,1,3,4])

Key concepts

sliding_windowarrayscounting

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.