Array Sum Limit

Randomize an array such that the sum of elements is fixed

Array Sum Limit (Total Sum = 100)

Problem Statement

Given an array of 10 elements where each element is in the range 0, 100, ensure that the total sum of all array elements equals exactly 100.

Your task is to generate or validate an array that satisfies this constraint.

Constraints

  • Array size: 10
  • Each element: 0 ≤ element ≤ 100
  • Sum of all elements: exactly 100

Examples

Example 1:

[10, 10, 10, 10, 10, 10, 10, 10, 10, 10]
Valid
Explanation: Sum = 10*10 = 100

Example 2:

[100, 0, 0, 0, 0, 0, 0, 0, 0, 0]
Valid
Explanation: Sum = 100 + 0*9 = 100

Example 3:

[50, 25, 15, 5, 2, 1, 1, 1, 0, 0]
Valid
Explanation: Sum = 50 + 25 + 15 + 5 + 2 + 1 + 1 + 1 = 100

Example 4:

[10, 10, 10, 10, 10, 10, 10, 10, 10, 5]
Invalid
Explanation: Sum = 95, not equal to 100

Example 5:

[50, 50, 0, 0, 0, 0, 0, 0, 0, 0]
Valid
Explanation: Sum = 50 + 50 = 100

Loading the interactive workspace...