Problem · Array

Temporal Anomalies

Learn this problem
HardInMobi logoInMobiFULLTIMEOA

Problem 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 >= xj
  • yi >= yj
  • zi >= 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 <= 100000
  • anomalies[i].length == 4
  • 1 <= anomalies[i][0], anomalies[i][1], anomalies[i][2] <= 100000
  • 1 <= anomalies[i][3] <= 10000

More InMobi problems

drafts saved locally
public long[] calculateAnomalyScores(int[][] anomalies) {
    // write your code here.
}
anomalies[[1,1,1,5],[2,2,2,10],[1,3,2,4],[3,1,1,2]]
expected[5,15,9,7]
checking account