FastPrepMinimize Adjacent Squared-Difference Cost with One Insertion
Problems/Minimize Adjacent Squared-Difference Cost with One Insertion

Minimize Adjacent Squared-Difference Cost with One Insertion

Scale AI logoScale AI● MediumNEW GRADOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Scale AI online assessment. The report asks you to insert one value to make the adjacent squared-difference loss as small as possible, and it gives the example [1,4,7,4]. We added the limits and the function signature. Our version is about 90% the same as the reported question.

The cost of an integer array is the sum of (values[i]-values[i-1])² over all adjacent pairs.

Insert exactly one integer at any position, including either end, and return the minimum possible cost. The inserted integer may be any signed 32-bit value.

Function

minimumSquaredDifferenceCost(values: int[]) → long

Examples

Example 1

values = [1,4,7,4]return = 23

Insert 5 between 4 and 7: 9+1+4+9=23.

Example 2

values = [1,5]return = 8

Insert 3 and split a gap of four into two gaps of two.

Example 3

values = []return = 0

After insertion, an originally empty array still has no adjacent pair.

Constraints

  • 0 <= values.length <= 100000.
  • -1000000000 <= values[i] <= 1000000000.
  • The answer fits in a signed 64-bit integer.

More Scale AI Online Assessment questions

  • Part 2: Batch Access ReviewOA · Seen Nov 2026
  • Part 1: The Narrowest KeyOA · Seen Nov 2026
  • Build Sessions from Unordered Events (Part 1)OA · Seen Oct 2026
  • Match Billing Charges to User Sessions (Part 2)OA · Seen Oct 2026
  • Four-Player Trick-Taking Card Game SimulationOA · PHONE SCREEN · Seen Aug 2026
  • Free Windows Between Busy IntervalsOA · PHONE SCREEN · Seen Apr 2026
  • Compare Labeling Worker AnnotationsOA · Seen Mar 2025
  • Count Stable Server SubsegmentsOA · Seen Nov 2024
  • Distinct OR Values of Increasing SubsequencesOA · Seen Nov 2024
  • Running Through Walls with Limited EnergyOA · Seen Sep 2024

Similar questions at other companies

  • Minimum Rounds to Complete All TasksInfosys · OAInfosys interview questions
  • Minimize Adjacent Squared-Difference Cost with One InsertionMcKinsey & Company · OAMcKinsey & Company interview questions
  • Maximize Revenue from Decreasing InventoryChubb · OAChubb interview questions
  • Minimum Values with Even Powers of TwoVisa · OAVisa interview questions
  • Minimize Adjacent Squared-Difference Cost with One InsertionMicrosoft · OAMicrosoft interview questions
  • Minimum Halvings for Alternating ParityIBM · OAIBM interview questions
  • Resource AllocationMaven Securities · OAMaven Securities interview questions
  • Rock JumpingIMC Trading · OAIMC Trading interview questions
  • Minimum Total Batch ExpenseAmazon · OA
  • Coprime Pick with Change CostCitadel · OACitadel interview questions

Interview reports that mention this question

  • Scale AI OA: What It Tests (2026)
  • Scale AI New Grad SWE and MLE Question Bank
  • Scale AI New Grad OA: Three Coding Problems

Scale AI interview experiences

  • Scale AI Forward Deployed Engineer Debugging Round: 1 Experience
  • Scale AI ML Research Engineering Intern Interviews: 1 Experience
  • Scale AI SWE Intern Debugging Interview: 9 Experiences
All Scale AI interview questionsSee Scale AI hiring insights
Saved
class Solution {
    public long minimumSquaredDifferenceCost(int[] values) {
        // write your code here
    }
}
Checking account…