Reported May 2025
Wells Fargohash table

Count Array Element Frequencies

Reported by candidates from Wells Fargo's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Wells Fargo OA. Under 2s to a working solution.
Founder's read

The first thing this Wells Fargo OA, reported in May 2025, tests is whether you reach for a hash map without thinking. Count Array Element Frequencies is a hash-table problem with a sorting step bolted on the end. Count each value, then emit [value, frequency] rows ordered by value. It's short, and it's easy to overthink with 10^5 elements and values up to 10^9 in magnitude. If you blank on the exact output shape mid-assessment, StealthCoder runs invisibly as a desktop overlay and can hand you the solution live. Most people won't need it here.

The problem

Given an integer array values, count how many times each distinct value appears.
Return a two-dimensional integer array in which each row is [value, frequency]. Sort the rows by value in ascending order.

Function
countFrequencies(values: int[]) → int[][]

Examples
Example 1
values = [4,2,4,3,2,4]
return = [[2,2],[3,1],[4,3]]
The value 2 appears twice, 3 appears once, and 4 appears three times.
Example 2
values = [-1,-1,0,5,0]
return = [[-1,2],[0,2],[5,1]]
Negative and zero values are counted normally, and rows remain ordered by value.
Example 3
values = [7]
return = [[7,1]]
The only value appears once.

Constraints
1 <= values.length <= 10^5.
-10^9 <= values[i] <= 10^9.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is a hash map from value to count. One pass over the array builds it in O(n). Then pull out the keys, sort them ascending, and build the rows. Total cost is O(n + k log k), where k is the number of distinct values. Don't use a fixed-size counting array. Values range from -10^9 to 10^9, so that blows up memory. Another pitfall is sorting the original array first and then scanning runs. It works, but it's slower to write cleanly and easier to get wrong. Watch negatives and zero, which the examples call out. Return type is a 2D int array, so size it to k rows. In a language with a sorted map, you can skip the explicit sort. If the Wells Fargo OA clock is tight and your hands freeze, StealthCoder is the hedge sitting quietly on your screen. This one should take about ten minutes.

Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.

If this hits your live OA

You can drill Count Array Element Frequencies cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Wells Fargo's OA.

Wells Fargo reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Count Array Element Frequencies FAQ

How hard is Count Array Element Frequencies really?+

Easy. It's a frequency count plus a sort on keys. The only real risk is sloppy output formatting or picking a data structure that can't handle negatives or values up to a billion. If you know hash maps, you're fine.

What's the trick to solving it?+

Use a hash map to count occurrences in one pass. Then sort the distinct keys ascending and build [value, frequency] rows from them. Sorting only the distinct keys keeps it efficient. That's the whole solution, with no clever insight needed.

Why can't I just use a counting array?+

Values go from -10^9 to 10^9, so a direct-index array would need billions of slots. A hash map only stores values that actually appear, so memory scales with distinct values, at most 10^5 here.

What's the time complexity I should aim for?+

O(n + k log k), where k is the count of distinct values. Worst case k equals n, so it's O(n log n), which is fine for 10^5 elements. A brute-force nested count would be O(n^2) and risks timing out.

How do I prepare for this in 48 hours?+

Write it once in your main language from scratch. Practice building a map, extracting and sorting keys, and returning a 2D array. Test with negatives, zero, and a single element. Then spend remaining time on harder array and hash problems.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Wells Fargo.

OA at Wells Fargo?
Invisible during screen share
Get it