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 = 100Example 2:
[100, 0, 0, 0, 0, 0, 0, 0, 0, 0]
Valid
Explanation: Sum = 100 + 0*9 = 100Example 3:
[50, 25, 15, 5, 2, 1, 1, 1, 0, 0]
Valid
Explanation: Sum = 50 + 25 + 15 + 5 + 2 + 1 + 1 + 1 = 100Example 4:
[10, 10, 10, 10, 10, 10, 10, 10, 10, 5]
Invalid
Explanation: Sum = 95, not equal to 100Example 5:
[50, 50, 0, 0, 0, 0, 0, 0, 0, 0]
Valid
Explanation: Sum = 50 + 50 = 100Loading the interactive workspace...