Count Pairs That Form a Complete Day II - Problem
Given an integer array hours representing times in hours, return an integer denoting the number of pairs i, j where i < j and hours[i] + hours[j] forms a complete day.
A complete day is defined as a time duration that is an exact multiple of 24 hours. For example, 1 day is 24 hours, 2 days is 48 hours, 3 days is 72 hours, and so on.
Input & Output
Example 1 — Basic Case
$
Input:
hours = [12,12,30,24,24]
›
Output:
2
💡 Note:
The valid pairs are (0,1) where 12+12=24 and (3,4) where 24+24=48. Both sums are multiples of 24.
Example 2 — Mixed Remainders
$
Input:
hours = [72,48,24,3]
›
Output:
3
💡 Note:
Valid pairs: (0,3) gives 72+3=75=24×3+3, wait that's wrong. Let me recalculate: 72%24=0, 48%24=0, 24%24=0, 3%24=3. We need pairs that sum to multiple of 24. Actually (0,1): 72+48=120=24×5, (0,2): 72+24=96=24×4, (1,2): 48+24=72=24×3. So answer is 3.
Example 3 — No Valid Pairs
$
Input:
hours = [1,2,3,4]
›
Output:
0
💡 Note:
No pair sums to a multiple of 24: 1+2=3, 1+3=4, 1+4=5, 2+3=5, 2+4=6, 3+4=7. None are divisible by 24.
Constraints
- 1 ≤ hours.length ≤ 5 × 105
- 1 ≤ hours[i] ≤ 109
Visualization
Tap to expand
Understanding the Visualization
1
Input Hours
Array of hours: [12, 12, 30, 18, 6]
2
Find Pairs
Check which pairs sum to multiples of 24
3
Count Result
Return total number of valid pairs
Key Takeaway
🎯 Key Insight: Two hours form a complete day if their sum is divisible by 24
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code