Find Missing Observations - Problem
The Mystery of the Missing Dice Rolls 🎲
Imagine you're analyzing data from
Here's what you still have:
• An array
• The average value of ALL
• The number
Your mission: Reconstruct the missing
If it's possible to find such values, return any valid array of length
Key insight: Since we know the average, we can calculate the total sum needed, then figure out how to distribute the missing values!
Imagine you're analyzing data from
n + m six-sided dice rolls, but disaster strikes - you've lost the records for n of them! 😱Here's what you still have:
• An array
rolls containing the values of the m dice rolls you didn't lose• The average value of ALL
n + m dice rolls (called mean)• The number
n representing how many dice rolls went missingYour mission: Reconstruct the missing
n dice roll values such that when combined with your existing m rolls, the average equals exactly mean. Each die shows a value between 1 and 6.If it's possible to find such values, return any valid array of length
n. If it's mathematically impossible, return an empty array.Key insight: Since we know the average, we can calculate the total sum needed, then figure out how to distribute the missing values!
Input & Output
example_1.py — Basic Case
$
Input:
rolls = [3,2,4,3], mean = 4, n = 2
›
Output:
[6,6]
💡 Note:
Current sum: 3+2+4+3 = 12. Total needed: 4×(4+2) = 24. Missing sum: 24-12 = 12. With n=2 dice, we need 12÷2 = 6 each. Since 6 is valid (1≤6≤6), return [6,6].
example_2.py — Distribution Case
$
Input:
rolls = [1,5,6], mean = 3, n = 4
›
Output:
[2,3,2,2]
💡 Note:
Current sum: 1+5+6 = 12. Total needed: 3×(3+4) = 21. Missing sum: 21-12 = 9. With n=4, base = 9÷4 = 2, remainder = 1. So we get [3,2,2,2] (first die gets 2+1=3).
example_3.py — Impossible Case
$
Input:
rolls = [1,2,3,4], mean = 6, n = 4
›
Output:
[]
💡 Note:
Current sum: 1+2+3+4 = 10. Total needed: 6×(4+4) = 48. Missing sum: 48-10 = 38. But with n=4 dice, max possible is 6×4 = 24. Since 38 > 24, it's impossible.
Constraints
- m == rolls.length
- 1 ≤ n, m ≤ 105
- 1 ≤ rolls[i], mean ≤ 6
- Each die shows a value between 1 and 6 inclusive
- The solution array (if exists) should have exactly n elements
Visualization
Tap to expand
Understanding the Visualization
1
Calculate Missing Amount
Figure out total coins needed minus what we already have
2
Check Feasibility
Verify we can distribute coins with box constraints (1-6 per box)
3
Equal Distribution
Give each box the same base amount (missing_sum ÷ n)
4
Handle Leftovers
Distribute remaining coins one per box until exhausted
Key Takeaway
🎯 Key Insight: Use mathematics instead of brute force - calculate the exact sum needed, then distribute it optimally among the dice!
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code