Not sure what to study next?

Get a personalised quant interview roadmap built around your upcoming interviews, strengths and weaknesses.

Takes a few minutes. Start with your target role and firms.

← Programming questions
Easy / PYTHON

Frequency Counter in First-Seen Order

arrays · hash_maps · counting 12 minute study target

Not completed

Challenge

A stream contains repeated integer labels. Return one [value, count] pair for each distinct label, in the order in which that label first appeared. Do not sort the labels. The pair list, rather than a dictionary with integer keys, is the required return format.

Input and output contract

0 ≤ n ≤ 60,000; integer labels from -1,000,000 to 1,000,000; at most 1,000 distinct labels. Empty input returns [].

All tests follow this contract. You do not need to validate malformed input. Return the requested result from frequency_counter; printed output is not your answer. Standard-library tools are allowed. Implement your solution in Python 3.12.

Target complexity: O(n) expected time; O(u) auxiliary space, where u is distinct values

Return values are checked by type. Use the exact function name. Print output is not your answer. Tests have time and memory limits.

Public examples

Example 1

Arguments

[[4, 2, 4, -1, 2, 4]]

Expected return

[[4, 3], [2, 2], [-1, 1]]
Example 2

Arguments

[[]]

Expected return

[]
Example 3

Arguments

[[0, -2, 0, -2, 5]]

Expected return

[[0, 2], [-2, 2], [5, 1]]
Hint

A dictionary can remember both the count and the first insertion order.

The worked solution unlocks after completion, or with Premium access.

frequency_counter.pyPython 3.12

Drafts are saved to your account, not to shared browser storage.

Sign in to submit code and save progress.

Results

Your results will appear here.

Hidden tests reveal only their pass/fail status, never their inputs or expected outputs. Runtime is observed wall time—not an inferred complexity class.

Join our Newsletter and Receive the Latest Updates!

Main Links

Trade Courses Assessments Interview Prep Contact Us

Social Media

Facebook Instagram YouTube

Legal

Terms and Conditions Privacy Policy Privacy settings

Talent Acquisition

Looking to hire exceptional quant talent?
See how we can help.

© 2026 EverythingQuant. All Rights Reserved.