Dsa
Arrays
Easy
Count Element Frequencies
Given an array of integers, write a program to count the frequency of each element and print them in ascending order of the element values.
Input format:
- The first line contains an integer n, the length of the array.
- The second line contains n space-separated integers (the array).
Output format:
- Each line contains an element and its frequency, separated by a space, in ascending order of the element.
Example:
Input:
7
4 5 6 4 3 3 5
Output:
3 2
4 2
5 2
6 1
Key concepts
arrayscounting
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