Count Array Element Frequencies
Updated
Problem statement
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.
More Wells Fargo interview questions
- Count Server ReplacementsOA · PHONE SCREEN · Seen Feb 2026
- Minimum Remaining LengthOA · PHONE SCREEN · Seen Feb 2026
- Compare Calendar DatesPHONE SCREEN · Seen May 2025
- Single-Nested Valid Bracket SubstringsPHONE SCREEN · Seen Sep 2020
- Server Upgrade PlanningOA · Seen Nov 2026
- Student and Course EnrollmentOA · Seen Nov 2026
- Bond Interest Summary Above 3%OA · Seen Oct 2026
- Count Phrases Formed by Anagram ReplacementOA · Seen Oct 2026
- Event Statistics AggregatorOA · Seen Sep 2026
- Ordered Deployment Configuration ValidatorOA · Seen Sep 2026
Similar questions at other companies
- Majority ElementByteDance · PHONE SCREENByteDance interview questions
- Recommend Films from Viewers Who Watched Everything You DidBloomberg LP · PHONE SCREENBloomberg LP interview questions
- Shared Courses for Every Pair of StudentsCrunchyroll · PHONE SCREENCrunchyroll interview questions
- Employee Count Median, Mean and ModeClay · PHONE SCREEN
- Convert an Entry List to a MapEPAM · PHONE SCREENEPAM interview questions
- Values Exclusive to the Current UserMeta · PHONE SCREENMeta interview questions
- Count Values Appearing Exactly OnceAgoda · PHONE SCREENAgoda interview questions
- Top Two Users by Total Purchase AmountSnowflake · PHONE SCREENSnowflake interview questions
- Restaurant Vote LeadersZipRecruiter · PHONE SCREEN · ONSITE INTERVIEWZipRecruiter interview questions
- AI Role: Collection with Add and Remove OperationsApple · PHONE SCREENApple interview questions