Question bank › Arrays
Dsa Arrays Hard

Array Compression

You need to compress an array of integers by reducing consecutive duplicates to a single number followed by the count of duplicates. For example, the array [1, 1, 2, 3, 3, 3] should be compressed to '1 2 2 1 3 3'. Return the compressed array as a space-separated string of integers. Input format: - The first line contains an integer n (1 ≤ n ≤ 10^5) - the size of the array. - The second line contains n space-separated integers a[i] (0 ≤ a[i] ≤ 10^9). Output format: - A single line of space-separated integers representing the compressed array. Example: Input: 6 1 1 2 3 3 3 Output: 1 2 2 1 3 3

Key concepts

arrayscompressionfrequency count

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 Praxari's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.