Temporal Anomalies
Learn this problemProblem statement
Each temporal anomaly is represented by four integers [x, y, z, severity].
An anomaly i dominates an anomaly j when all three coordinates of i are greater than or equal to the corresponding coordinates of j:
xi >= xjyi >= yjzi >= zj
For every anomaly, compute the sum of the severities of all anomalies it dominates. An anomaly dominates itself. Anomalies with identical coordinates dominate one another.
Return the scores in the same order as the input rows.
Function
calculateAnomalyScores(anomalies: int[][]) → long[]Examples
Example 1
anomalies = [[1,1,1,5],[2,2,2,10],[1,3,2,4],[3,1,1,2]]return = [5,15,9,7]The second anomaly dominates itself and the first anomaly, giving 10 + 5 = 15. The third and fourth anomalies each dominate the first anomaly in addition to themselves.
Example 2
anomalies = [[2,2,2,3],[2,2,2,7],[1,2,2,5],[3,1,3,4]]return = [15,15,5,4]The first two anomalies have equal coordinates, so each dominates both of them and the third anomaly. Their common score is 3 + 7 + 5 = 15.
Example 3
anomalies = [[1,5,1,2],[1,3,2,4],[1,5,3,8],[2,4,3,16]]return = [2,4,14,20]The third anomaly dominates the first two and itself, for a score of 14. The fourth dominates the second and itself, for a score of 20; the other rows are incomparable with it in at least one coordinate.
Constraints
1 <= anomalies.length <= 100000anomalies[i].length == 41 <= anomalies[i][0], anomalies[i][1], anomalies[i][2] <= 1000001 <= anomalies[i][3] <= 10000