Sort Bug Report Frequencies
Learn this problemProblem statement
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.
The function sortBugReportFrequencies uses the following input:
Input: int bugs[n], an integer array of size n with each element denoting a bug code of an occurring bug.
Return value: int[n], an array of integers sorted in order of decreasing importance.
Function
sortBugReportFrequencies(bugs: int[]) → int[]Examples
Example 1
bugs = [8, 4, 6, 5, 4, 8]return = [5, 6, 4, 4, 8, 8]
Bugs with frequency 1 will come before the bugs with frequency 2.
(6, 5)comes before(8, 4, 4, 8), which results inbugs = [6, 5, 8, 4, 4, 8].
In the case of the same frequency, ties are broken by bug codes themselves.
5comes before6, and4comes before8, which results inbugs = [5, 6, 4, 4, 8, 8].
Constraints
1 ≤ n ≤ 2 * 10^51 ≤ bugs[i] ≤ 10^6
More Amazon problems
- Maximum Length-K Window Sum over Sparse SegmentsOA · Seen Aug 2026
- Drone Delivery RouteOA · Seen Jul 2026
- Detect a Keyword SubstringONSITE INTERVIEW · Seen Jul 2026
- Find Maximum Total Amount (SDE I, Fungible :)OA · Seen Jul 2026
- Find the Root of a Directed TreeONSITE INTERVIEW · Seen Jul 2026
- Meeting Rooms IIPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
- Merge IntervalsOA · ONSITE INTERVIEW · Seen Jul 2026
- Single Element in a Sorted ArrayPHONE SCREEN · Seen Jul 2026