Problem · Array

Sort Bug Report Frequencies

EasyAmazonINTERNOA
See Amazon hiring insights

You are helping Amazon's Quality Assurance engineers process bug reports generated from automated testing logs across various devices and services. Each log contains an integer bug code, and a single test session may include duplicate bug codes if the same issue is triggered multiple times.

To effectively prioritise debugging and resolution, the following rules are applied:

  • Less frequent bugs are considered more important, as they may indicate rare or edge-case issues.
  • If two bugs occur the same number of times, the bug with the lower code number has higher priority.

The task is to sort the bug codes in order of decreasing importance, using the above rules.

Function Description

The function sortBugReportFrequencies will take the following input:

int bugs[n]: An integer array of size n with each element denoting a bug code of an occurring bug.

Returns

int[n]: an array of integers sorted in order of decreasing importance

Examples
01 · Example 1
bugs = [8, 4, 6, 5, 4, 8]
return = [5, 6, 4, 4, 8, 8]

bugs = [8, 4, 6, 5, 4, 8].

Item CodeFrequency
82
42
61
51

Bugs with frequency 1 will come before the bugs with frequency 2.

  • (6, 5) comes before (8, 4, 4, 8), which results in bugs = [6, 5, 8, 4, 4, 8].

In the case of the same frequency, ties are broken by bug codes themselves.

  • 5 comes before 6, and 4 comes before 8, which results in bugs = [5, 6, 4, 4, 8, 8].
Constraints
  • 1 <= n <= 2 * 10^5
  • 1 <= bugs[i] <= 10^6
More Amazon problems
drafts saved locally
public int[] sortBugReportFrequencies(int[] bugs) {
  // write your code here
}
bugs[8, 4, 6, 5, 4, 8]
expected[5, 6, 4, 4, 8, 8]
sign in to submit