Window Sums by Tag

Asked at Datadog

Reported by the problem's creator, not verified

Import another question

A monitoring service receives datapoints from customers. Each datapoint is a [timestamp, tag, value] triple, and points from different tags are interleaved in one stream.

Examples

  1. Example 1

    Input: points = [[1,"tag",5],[2,"tag",4],[3,"tag",3],[4,"tag",2],[5,"tag",1]], k = 3

    Output: {"tag":[12,9,6]}

    Explanation: The windows cover values [5, 4, 3], [4, 3, 2] and [3, 2, 1], which sum to 12, 9 and 6.

  2. Example 2

    Input: points = [[1,"cpu",10],[2,"mem",1],[3,"cpu",20],[4,"mem",2],[5,"cpu",30],[6,"mem",3],[7,"mem",4]], k = 2

    Output: {"cpu":[30,50],"mem":[3,5,7]}

    Explanation: cpu has values [10, 20, 30], giving windows 30 and 50. mem has [1, 2, 3, 4], giving 3, 5 and 7.

Import your own questions
Paste a question you were asked and get a full problem: statement, tests and a checked solution.
Import a question

Code

Loading editor…

Ln 1, Col 1

Start an attempt to use Coach.