FastPrepDistribute Values by Distance from Current Averages
Problems/Distribute Values by Distance from Current Averages

Distribute Values by Distance from Current Averages

ZipRecruiter logoZipRecruiter● MediumNEW GRADOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A ZipRecruiter new-grad OA report describes seeding two arrays, comparing an average error for each later value, appending it to the side with the smaller error, and returning the first array followed by the second. We supplied the absolute distance to the arithmetic mean, an exact comparison of fractions, and ties going to the first side. Our version is about 82% the same as the reported question.

Initialize first with values[0] and second with values[1]. For every later value, compare its absolute distance from each array's current arithmetic mean and append it to the array with the smaller distance. Break an exact tie in favor of first.

Return first followed by second.

Function

distributeByAverage(values: int[]) → int[]

Examples

Example 1

values = [1,10,2,9,5]return = [1,2,5,10,9]

Later values are compared against evolving means.

Example 2

values = [0,10,5]return = [0,5,10]

Equal average distances choose the first array.

Constraints

  • 2 <= values.length <= 100000
  • -100000 <= values[i] <= 100000

More ZipRecruiter Online Assessment questions

  • Four-Level Banking System with Scheduled PaymentsOA · Seen Oct 2026
  • Count Three-Digit Numbers with Distinct DigitsOA · Seen Oct 2024
  • Longest Frequency-Bounded SubarrayOA · Seen Oct 2024
  • Minimum Changes to Draw a YOA · Seen Oct 2024
  • Apply Binary State OperationsOA · Seen Sep 2024
  • Simulate Orchard Rot SpreadOA · Seen Sep 2024
  • Compare Odd- and Even-Index SumsOA · Seen Sep 2024
  • Coordinate Removals with Column GravityOA · Seen Sep 2024
  • Lexicographically Smallest End ReversalOA · Seen Sep 2024
  • Recursively Expanded Shell Command CountsOA · Seen Sep 2024

Similar questions at other companies

  • Bank Accounts with Balance HistoryMeta · OAMeta interview questions
  • Capping Portfolio WeightsCapstone Investment Advisors · OA
  • Repeated Mirror XORMathWorks · OAMathWorks interview questions
  • Stacked Item and Category DiscountsPalantir · OAPalantir interview questions
  • Stabilize Student Test ScoresVirtu Financial · OAVirtu Financial interview questions
  • Compress Editor Actions into Operational Transform OperationsReplit · OA · PHONE SCREEN · ONSITE INTERVIEW
  • Minimize Task Resource ConsumptionNVIDIA · OANVIDIA interview questions
  • Index of the Maximum After Left RotationsChubb · OAChubb interview questions
  • Leaves Remaining After WindCresta · OACresta interview questions
  • Rolling MetricsAkuna Capital · OAAkuna Capital interview questions

ZipRecruiter interview experiences

  • ZipRecruiter SWE OA, Level Not Reported: 23 Experiences
  • ZipRecruiter SWE Intern OA Scores: 4 Experiences
  • ZipRecruiter SWE New Grad OA: 9 Experiences
All ZipRecruiter interview questionsSee ZipRecruiter hiring insights
Saved
class Solution {
    public int[] distributeByAverage(int[] values) {
        // Write your code here.
    }

}
Checking account…