FastPrepMinimum Difference Sum
Problems/Minimum Difference Sum

Minimum Difference Sum

Oracle logoOracle● EasyFULLTIMEOA

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

Given an array of n integers, rearrange them so that the sum of the absolute differences of all adjacent elements is minimized. Then, compute the sum of those absolute differences.

Function

minDiff(arr: int[]) → int

Complete the function minDiff in the editor.

minDiff has the following parameter:

  1. int arr[]: an integer array

Returns int: the sum of the absolute differences of adjacent elements

Examples

Example 1

arr = [1, 3, 3, 2, 4]return = 3

If the list is rearranged as arr' = [1, 2, 3, 3, 4], the absolute differences are |1 - 2| = 1, |2 - 3| = 1, |3 - 3| = 0, |3 - 4| = 1. The sum of those differences is 1 + 1 + 0 + 1 = 3.

Constraints

  • 2 ≤ n ≤ 10^5
  • 0 ≤ arr[i] ≤ 10^9, where 0 ≤ i < n

More Oracle interview questions

  • Course ScheduleONSITE INTERVIEW · Seen Nov 2026
  • Shortest Subarray with Sum at Least KONSITE INTERVIEW · Seen Nov 2026
  • Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
  • Minimum Meeting RoomsONSITE INTERVIEW · Seen Nov 2026
  • Shortest Window with Required CountsONSITE INTERVIEW · Seen Nov 2026
  • Maximum Subarray Sum with One DeletionONSITE INTERVIEW · Seen Nov 2026
  • Shortest Deletion for Distinct CharactersONSITE INTERVIEW · Seen Nov 2026
  • Count Dropped Rate-Limited RequestsONSITE INTERVIEW · Seen Nov 2026
  • Remove Parentheses from a Plus-Minus ExpressionPHONE SCREEN · Seen Nov 2026
  • Design Authentication ManagerONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Catch Fish with Reusable BaitsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
  • Group Students (AS Intern, it may apply to other interns) 🍑Amazon · OA
  • Maximum Apples That Fit in a BoxVirtu Financial · OAVirtu Financial interview questions
  • Server ManagementRippling · OARippling interview questions
  • Maximum Three-Server Difficulty ScoreVisa · OAVisa interview questions
  • Economical TripAccenture · OAAccenture interview questions
  • Minimum Pile Reduction StepsAmerican Express · OAAmerican Express interview questions
  • Maximum Production Within PowerZomato / Eternal · OAZomato / Eternal interview questions
  • Can Every Package Fit in a BoxIMC Trading · OAIMC Trading interview questions
  • Compute Walking DistanceTikTok · OATikTok interview questions

Oracle interview experiences

  • Oracle SWE Onsite Interview Experience: 1 Experience
All Oracle interview questionsSee Oracle hiring insights
Saved
class Solution {
    public int minDiff(int[] arr) {
        // write your code here
    }

}
Checking account…