Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Coding: Sliding Window Function

MediumPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Coding: Sliding Window Function. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Datadog Metrics processing can group sequential three-dimensional coordinate values into fixed-size windows. Given an ordered sequence of 3D points and a window size k, return the coordinate-wise sum for every contiguous window of exactly k points.

The first output represents points 0 through k - 1. Each following window moves one position right, so update the previous sum by subtracting the point that leaves and adding the point that enters.

Formal Specification

Implement sliding_coordinate_sums(points, k).

  • Input points: a list of points, where each point is a list of exactly three integers [x, y, z].
  • Input k: a positive integer window size.
  • Output: a list of lists, where each output point is [sum_x, sum_y, sum_z] for one contiguous window.
  • Return an empty list when k is greater than the number of points.

Constraints

  • 0 <= points.length <= 10^5
  • Each point contains exactly three integers
  • 1 <= k <= 10^5
  • -10^9 <= points[i][j] <= 10^9
  • Return windows in their original left-to-right order

Function Signature

def sliding_coordinate_sums(points, k):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output