Count Frequency of Each Element in Array
E · easyP · Verified PYQarrayshashing
Problem
Given an array of N integers, count and print the frequency of each unique element in the order they first appear.
Example
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.