1035. Sort Threats
You are given a 2D integer array threats, where each threats[i] = [IDi, sevi, expi]
- IDi: Unique identifier of the threat.
- sevi: Indicates the severity of the threat.
- expi: Indicates the exploitability of the threat.
The score of a threat i is defined as: score = 2 × sevi + expi
Your task is to return threats sorted in descending order of score.
If multiple threats have the same score, sort them by ascending ID.
Example 1:
Input: threats = [[101, 2, 3], [102, 3, 2], [103, 3, 3]]
Output: [[103, 3, 3], [102, 3, 2], [101, 2, 3]]
Explanation:
- threats [0]: ID: 101, sev: 2, exp: 3, Score = $2 \times 2 + 3 = 7$
- threats [1]: ID: 102, sev: 3, exp: 2, Score = $2 \times 3 + 2 = 8$
- threats [2]: ID: 103, sev: 3, exp: 3, Score = $2 \times 3 + 3 = 9$
Sorted Order: [[103, 3, 3], [102, 3, 2], [101, 2, 3]]
Example 2:
Input: threats = [[101, 4, 1], [103, 1, 5], [102, 1, 5]]
Output: [[101, 4, 1], [102, 1, 5], [103, 1, 5]]
Explanation:
- threats [0]: ID: 101, sev: 4, exp: 1, Score = $2 \times 4 + 1 = 9$
- threats [1]: ID: 103, sev: 1, exp: 5, Score = $2 \times 1 + 5 = 7$
- threats [2]: ID: 102, sev: 1, exp: 5, Score = $2 \times 1 + 5 = 7$
threats [1] and threats [2] have same score, thus sort them by ascending ID.
Sorted Order: [[101, 4, 1], [102, 1, 5], [103, 1, 5]]
Now Your Turn!
Pick the correct output for the given inputInput: threats = [[1, 2, 3],[4, 5, 6],[7, 8, 9]]
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
- 1 <= threats.length <= 105
- threats[i] == [IDi, sevi, expi]
- 1 <= IDi <= 106
- 1 <= sevi <= 109
- 1 <= expi <= 109
- All IDi are unique