[LeetCode] Sort Threats by Severity and Exploitability

3631. Sort Threats by Severity and Exploitability

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.

1
2
3
4
5
6
7
8
9
10
11
class Solution {
public:
vector<vector<int>> sortThreats(vector<vector<int>>& threats) {
sort(begin(threats), end(threats), [](auto& a, auto& b) {
long long sa = 2ll * a[1] + a[2], sb = 2ll * b[1] + b[2];
if(sa != sb) return sa > sb;
return a[0] < b[0];
});
return threats;
}
};
Author: Song Hayoung
Link: https://songhayoung.github.io/2025/11/27/PS/LeetCode/sort-threats-by-severity-and-exploitability/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.