Problem Brief

Items Sort

INTERNOA

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.

Function Description

Complete the function itemsSort in the editor below.

itemsSort has the following parameter(s):

  1. int items[n]: the array to sort

Returns

int[n]: the sorted array

1Example 1

Input
items = [4, 5, 6, 5, 4, 3]
Output
[3, 6, 4, 4, 5, 5]
Explanation

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

Limits and guarantees your solution can rely on.

1 ≤ n ≤ 2 x 105
1 ≤ items[i] ≤ 106
public int[] itemsSort(int[] items) {
  // write your code here
}
Input

items

[4, 5, 6, 5, 4, 3]

Output

[3, 6, 4, 4, 5, 5]

Sign in to submit your solution.