Unique Sum
Unique Sum Constraint
Unique Sum Constraint
Problem Statement
Generate an array of unique integers where the sum of all elements equals a specific target. This combines uniqueness constraint with sum constraint, making the solution space more constrained and realistic.
Your task is to write constraints where: 1. All array elements are unique (no duplicates) 2. Each element is in range 1, 10 3. The sum of all elements equals 21
Constraints
- Array size: 6 elements
- Element range: 1, 10 (positive integers)
- All elements must be unique
- Target sum: 21
- Example: {1, 2, 3, 4, 5, 6} sums to 21
Examples
Example 1:
Array: [1, 2, 3, 4, 5, 6]
Sum: 21
All Unique: YesExplanation: Consecutive integers from 1-6 sum to 21.
Example 2:
Array: [1, 2, 3, 4, 5, 6]
Sum: 21
All Unique: YesExplanation: Each element appears exactly once, no duplicates.
Example 3:
Array: [1, 2, 5, 6, 3, 4]
Sum: 21
All Unique: YesExplanation: Same elements in different order.
Example 4 (Invalid):
Array: [5, 5, 2, 3, 4, 1]
Sum: 20
ā INVALID: Element 5 appears twice, Sum is 20Explanation: Violates both uniqueness and sum constraints.
Starter Code Pointer
The constraint logic demonstrates:
1. Combining multiple constraints (range, uniqueness, sum)
2. Using unique {} for uniqueness constraint
3. Complex constraint satisfaction with limited solution space
Loading the interactive workspace...