Array Index Sum Limit
Sum of even and odd indices must be constant
Array Index Sum Limits
Problem Statement
Given an array of 10 elements with values in range 0, 77, split the elements into two groups: 1. Even-indexed elements: indices 0, 2, 4, 6, 8 (sum must equal exactly 77) 2. Odd-indexed elements: indices 1, 3, 5, 7, 9 (sum must equal exactly 39)
Your task is to generate an array that satisfies both sum constraints.
Constraints
- Array size: 10 elements
- Each element: 0 ≤ element ≤ 77
- Sum of even-indexed elements: 77
- Sum of odd-indexed elements: 39
Examples
Example 1:
Input: Generate valid array
Output: [77, 39, 0, 0, 0, 0, 0, 0, 0, 0]
Explanation:
- Even indices (0,2,4,6,8): 77+0+0+0+0 = 77 ✓
- Odd indices (1,3,5,7,9): 39+0+0+0+0 = 39 ✓Example 2:
Input: Generate valid array (more distributed)
Output: [20, 10, 15, 10, 20, 10, 15, 5, 7, 4]
Explanation:
- Even indices: 20+15+20+15+7 = 77 ✓
- Odd indices: 10+10+10+5+4 = 39 ✓Example 3:
Input: [50, 20, 15, 10, 12, 5, 0, 4, 0, 0]
Valid
Explanation:
- Even indices: 50+15+12+0+0 = 77 ✓
- Odd indices: 20+10+5+4+0 = 39 ✓Example 4:
Input: [40, 20, 20, 10, 17, 5, 0, 4, 0, 0]
Invalid
Explanation:
- Even indices: 40+20+17+0+0 = 77 ✓
- Odd indices: 20+10+5+4+0 = 39 ✓ (Wait, this should be valid!)
Actually, let me recalculate: 40+20+17+0+0 = 77 ✓, 20+10+5+4+0 = 39 ✓ - This IS validExample 5:
Input: [38, 20, 20, 10, 19, 5, 0, 4, 0, 0]
Invalid
Explanation:
- Even indices: 38+20+19+0+0 = 77 ✓
- Odd indices: 20+10+5+4+0 = 39 ✓ (This would be valid)
Let me pick a different one...
Validate [40, 20, 19, 10, 17, 5, 0, 4, 0, 0]
- Even indices: 40+19+17+0+0 = 76 ✗ (should be 77)Loading the interactive workspace...