FastPrepMaximum Three-Server Difficulty Score
Problems/Maximum Three-Server Difficulty Score

Maximum Three-Server Difficulty Score

Visa logoVisa● EasyNEW GRADINTERNOA
QuestionFunctionExamplesConstraints

Problem statement

Source note: The source gives the two-term score and extreme-value strategy but omits numeric bounds and initially describes the score more broadly. The judged core task matches the report at about 92%.

You are given an integer array difficulty, where each value is the difficulty of one module.

Distribute all modules among three labeled servers. Every module must be assigned to exactly one server, and each server must receive at least one module. Then choose one module from each server. Let their difficulties, in server order, be d1, d2, and d3.

The score is |d1 - d2| + |d2 - d3|. Return the maximum score obtainable over all valid distributions and choices.

FastPrep practice interpretation: The explicit two-term formula and the reported extreme-value strategy determine the judged score. The selected modules must be three distinct array elements, although equal difficulty values are allowed.

Function

maximumDifficultyScore(difficulty: int[]) → long

Examples

Example 1

difficulty = [1,4,7,10]return = 15

Place difficulties 1, 10, and 4 on servers one, two, and three. The score is |1 - 10| + |10 - 4| = 9 + 6 = 15.

Example 2

difficulty = [5,5,5]return = 0

Every selected difficulty is 5, so both absolute differences are 0.

Example 3

difficulty = [2,3,100]return = 195

Use 100 as d2 and the other two values as the endpoints. The score is |2 - 100| + |100 - 3| = 98 + 97 = 195.

Constraints

  • 3 <= difficulty.length <= 100000
  • 1 <= difficulty[i] <= 10^9

More Visa problems

  • Count Prime Values in SubtreesOA · Seen Nov 2026
  • Minimum-Sum Tree Fill with Unit StepsOA · Seen Nov 2026
  • House RobberPHONE SCREEN · Seen Nov 2026
All Visa interview questionsSee Visa hiring insights
Saved
class Solution {
    public long maximumDifficultyScore(int[] difficulty) {
      // Write your code here.
    }

}
Checking account…