FastPrepPercentile and Boundary Queries
Problems/Percentile and Boundary Queries

Percentile and Boundary Queries

Datadog logoDatadog● MediumFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: The firsthand report describes finding a boundary for a percentile and, as a follow-up, finding a value's percentile. Its boundary table and formulas are not reproduced. This practice version defines paired calibration anchors, linear interpolation on both axes, clamping, the callable adapter and bounds. These are authored details, not recovered original examples. The core task matches the report at about 70%.

A calibration table pairs each numeric boundaries[i] with percentiles[i]. Between adjacent pairs, the relationship is linear. This table is the full model for this exercise; no raw samples or bucket counts are supplied.

Answer every request using the same table:

  • If inverse is false, each request is a percentile and you return its numeric boundary value.
  • If inverse is true, each request is a numeric value and you return its percentile.

At a table anchor, return the paired value exactly. Between two anchors, use the same fraction of the interval on the other axis. Clamp a request below the input axis range to its first paired value, and one above the range to its last paired value. Preserve request order. An empty request array returns an empty result.

This is a piecewise-linear calibrated percentile model, rather than a nearest-rank percentile over raw samples. Its interpolation, inverse and endpoint rules are specified here for practice.

Function

percentileBoundaryQueries(boundaries: double[], percentiles: double[], requests: double[], inverse: boolean) → double[]

Examples

Example 1

boundaries = [0,10,30]percentiles = [0,50,100]requests = [25,50,75,0,100]inverse = falsereturn = [5,10,20,0,30]

Percentile 25 is halfway between 0 and 50, so its value is halfway between 0 and 10: 5. The anchor 50 maps to 10. Percentile 75 maps to 20. Endpoints map to 0 and 30.

Example 2

boundaries = [0,10,30]percentiles = [0,50,100]requests = [5,10,20,-5,40]inverse = truereturn = [25,50,75,0,100]

Value 5 is halfway through the first interval, giving percentile 25. Value 10 is the 50 anchor. Value 20 is halfway from 10 to 30, giving 75. Values outside the table range clamp to 0 and 100.

Example 3

boundaries = [-10,0,30]percentiles = [0,20,100]requests = [10,60,120]inverse = falsereturn = [-5,15,30]

Percentile 10 lies halfway through the first percentile interval and maps to -5. Percentile 60 lies halfway from 20 to 100 and maps to 15. Percentile 120 is above the modeled range and clamps to the final value 30.

Constraints

  • 2 <= boundaries.length <= 101
  • boundaries.length == percentiles.length
  • 0 <= requests.length <= 100
  • Every boundary and request is between -1000000 and 1000000, inclusive.
  • Every percentile is between 0 and 100, inclusive.
  • Both boundary and percentile arrays are strictly increasing.
  • The first percentile is 0 and the last is 100.
  • All numbers are finite.

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[] percentileBoundaryQueries(double[] boundaries, double[] percentiles, double[] requests, boolean inverse) {
    // Write your code here.
}
Checking account…