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 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
bugs = [8, 4, 6, 5, 4, 8] return = [5, 6, 4, 4, 8, 8]
bugs = [8, 4, 6, 5, 4, 8].
| Item Code | Frequency |
|---|---|
| 8 | 2 |
| 4 | 2 |
| 6 | 1 |
| 5 | 1 |
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].
1 <= n <= 2 * 10^51 <= bugs[i] <= 10^6
- Maximum Equal Parts for PrefixesOA · Seen Jun 2026
- Count Promotional PeriodsOA · Seen Jun 2026
- Find Maximum Total Amount (SDE I, Fungible :)Seen Jun 2026
- Get Minimum AmountOA · Seen Jun 2026
- Find Minimum CostOA · Seen Jun 2026
- Get Smallest Base SegmentOA · Seen Jun 2026
- Maximum Non-Adjacent House ValueONSITE INTERVIEW · Seen Jun 2026
- Running Delivery Time MediansONSITE INTERVIEW · Seen Jun 2026
public int[] sortBugReportFrequencies(int[] bugs) {
// write your code here
}