Problem · Array
Items Sort
Given an array of n item values, sort the array in ascending order, first by the frequency of each value, then by the values themselves.
Complete the function itemsSort in the editor below.
itemsSort has the following parameter(s):
int items[n]: the array to sort
Returns
int[n]: the sorted array
Examples
01 · Example 1
items = [4, 5, 6, 5, 4, 3] return = [3, 6, 4, 4, 5, 5]
There are 2 values that occur once: [3, 6].
There are 2 values that occur twice: [4, 4, 5, 5].
The array of items sorted by frequency and then by value in ascending order is [3, 6, 4, 4, 5, 5].
Constraints
1 ≤ n ≤ 2 x 105
1 ≤ items[i] ≤ 106More Akuna Capital problems
- Maximum DifferenceOA · Seen May 2026
- Nearest Neighbouring CitySeen Oct 2024
- Future Stock PricesSeen Oct 2024
- Delivery Management System (QR Intern)Seen Sep 2024
- Array Challenge (QR Intern)Seen Sep 2024
- Update Release Scheduler (QR Intern)Seen Sep 2024
- Binary CircuitSeen Aug 2024
- K Smallest SubstringSeen Aug 2024
public int[] itemsSort(int[] items) {
// write your code here
}
items[4, 5, 6, 5, 4, 3]
expected[3, 6, 4, 4, 5, 5]
sign in to submit