Count Frequency of Each Element in Array

E · easyP · Verified PYQarrayshashing

Given an array of N integers, count and print the frequency of each unique element in the order they first appear.

Input
6
1 2 2 3 1 4
Output
1 occurs 2 times
2 occurs 2 times
3 occurs 1 times
4 occurs 1 times
Use OrderedDict or list of seen elements + dict to preserve first-occurrence order.
← Count Even and Odd Numbers in ArrayCount Frequency of Element in Array →
Report an issue with this question