FastPrepTagged Metric Window Sums
Problems/Tagged Metric Window Sums

Tagged Metric Window Sums

Datadog logoDatadog● MediumFULLTIMEPHONE SCREENONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: Reports describe tag filtering, time sorting, count-based sums and complete time windows. This exercise uses the filtered-series cutoff supported by the reported example and clarification. The callable, equal-time rules, decimal precision and bounds are specified for practice. The core task matches the reports at about 85%.

Metric datapoints are given by parallel arrays. Point i has tag list tags[i], timestamp timestamps[i], and value values[i]. Keep a point if its tag list contains tag as an exact, case-sensitive string. A repeated tag on the same point keeps that point only once.

Sort the matching points by timestamp. For equal timestamps, keep their original input order. Compute window sums according to timeBased:

  • If false, k is a number of points. Return the sum of every consecutive group of exactly k matching points. If fewer than k match, return an empty array.
  • If true, k is a duration. For each matching point at time t, sum all matching points with timestamps in the inclusive interval [t, t + k]. Include that sum only if t + k is at most the last timestamp in the filtered series. Equal-time points each start a window, so their sums may be identical.

Return the sums in sorted starting-point order. In time mode, points with the same start timestamp are all included in that interval, including those before the particular anchor in the sorted list. Unmatched points do not extend the filtered time range. An empty filtered series returns an empty array.

Function

taggedWindowSums(tags: String[][], timestamps: long[], values: double[], tag: String, k: int, timeBased: boolean) → double[]

Examples

Example 1

tags = [["env:dev"],["env:dev"],["env:prod","host:a"],["env:dev"],["env:dev","host:a"],["env:dev"],["env:staging","host:a"],["env:dev"],["env:dev"],["env:dev"],["env:staging"]]timestamps = [0,1,2,3,6,7,9,10,11,14,15]values = [1,3,5,-1,-3,5,-3,-4,6,-1,10]tag = "env:dev"k = 3timeBased = falsereturn = [3.0,-1.0,1.0,-2.0,7.0,1.0]

Filtering keeps eight env:dev points. The six groups sum to 1 + 3 - 1 = 3, 3 - 1 - 3 = -1, -1 - 3 + 5 = 1, -3 + 5 - 4 = -2, 5 - 4 + 6 = 7, and -4 + 6 - 1 = 1.

Example 2

tags = [["env:dev"],["env:dev"],["env:prod","host:a"],["env:dev"],["env:dev","host:a"],["env:dev"],["env:staging","host:a"],["env:dev"],["env:dev"],["env:dev"],["env:staging"]]timestamps = [0,1,2,3,6,7,9,10,11,14,15]values = [1,3,5,-1,-3,5,-3,-4,6,-1,10]tag = "env:dev"k = 3timeBased = truereturn = [3.0,2.0,-4.0,2.0,1.0,2.0,5.0]

The matching series ends at 14; the point at 15 has no env:dev tag. Starts 0, 1, 3, 6, 7, 10, 11 have complete intervals ending at 3, 4, 6, 9, 10, 13, 14. Their sums are 3, 2, -4, 2, 1, 2, 5. A start at 14 would end at 17, beyond the last matching timestamp 14, so it is omitted.

Example 3

tags = [["env:dev"],["env:prod"],["env:dev","host:a"],["env:dev"]]timestamps = [4,100,0,4]values = [1.25,99.0,-0.5,2.0]tag = "env:dev"k = 2timeBased = falsereturn = [0.75,3.25]

The matching values in sorted order are -0.5, 1.25, 2.0. The two points at time 4 retain their original order. The consecutive two-point sums are 0.75 and 3.25.

Example 4

tags = [["env:dev"],["env:prod"],["env:dev","host:a"],["env:dev"]]timestamps = [4,100,0,4]values = [1.25,99.0,-0.5,2.0]tag = "env:dev"k = 4timeBased = truereturn = [2.75]

The filtered time range ends at 4; the unmatched point at time 100 does not extend it. Only the start at 0 has a complete four-unit interval. It includes all three matching values, whose sum is 2.75. Both starts at 4 are omitted.

Constraints

  • 0 <= tags.length <= 500
  • tags.length == timestamps.length and tags.length == values.length
  • 0 <= tags[i].length <= 8
  • 1 <= tags[i][j].length <= 64
  • 1 <= tag.length <= 64
  • 0 <= timestamps[i] <= 1000000000
  • -1000000 <= values[i] <= 1000000
  • 1 <= k <= 1000000000
  • Every value has at most two decimal places.
  • All tag strings contain only printable ASCII characters. Matching preserves spaces and capitalization.
  • The sum of the lengths of all strings in tags is at most 20000.
  • timeBased is a boolean.

More Datadog problems

  • Query Log MatchPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Delete a Filesystem TreePHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
  • Grouped-Query Attention Forward PassPHONE SCREEN · Seen Jun 2026
All Datadog interview questionsSee Datadog hiring insights
Saved
public double[] taggedWindowSums(String[][] tags, long[] timestamps, double[] values, String tag, int k, boolean timeBased) {
    // write your code here
}
Checking account…