Problem · Array
Sort Array by Frequency
Learn this problemProblem statement
Given an integer array items, sort all of its elements using these rules:
- Values with a lower occurrence frequency come before values with a higher frequency.
- When two values have the same frequency, the smaller numeric value comes first.
Return the sorted array.
Function
sortByFrequency(items: int[]) → int[]Examples
Example 1
items = [6,5,4,5,4,8]return = [6,8,4,4,5,5]The values 6 and 8 each appear once, so they come first in ascending order. The values 4 and 5 each appear twice, so their two copies follow in ascending value order.
Example 2
items = [-1,2,-1,2,3]return = [3,-1,-1,2,2]The value 3 appears once. Both -1 and 2 appear twice, so -1 comes before 2.
More Akuna Capital problems
- Binary CircuitSeen Jul 2026
- Minimize Malware Spread by Removing a NodeOA · Seen Jul 2026
- Array Challenge (QR Intern)OA · Seen Jul 2026
- Communications HandlerOA · Seen Jul 2026
- K Smallest SubstringOA · Seen Jul 2026
- Maximum K-Star SumOA · Seen Jul 2026
- Delivery Management SystemOA · Seen Jul 2026
- Minimum SwapsOA · Seen Jul 2026