Dsa
Arrays
Easy
Consecutive Run Length Encoding
Implement a program that takes an integer array and compresses it using run-length encoding. The input will be given in the following format:
- The first line will contain n (1 <= n <= 1000).
- The second line will contain n integers, which are the elements of the array. Each element can be at most 1000.
Output a single line with the run-length encoded format: 'element:count' pairs, separated by spaces.
Example:
Input:
5
1 1 2 2 2
Output:
1:2 2:3
Key concepts
arraysencodingcounting
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