Count Pairs That Form a Complete Day I - 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:
Valid pairs: (0,1) → 12+12=24, (3,4) → 24+24=48. Both sums are multiples of 24.
Example 2 — No Valid Pairs
$
Input:
hours = [72,48,24,3]
›
Output:
3
💡 Note:
Valid pairs: (0,1) → 72+48=120, (0,2) → 72+24=96, (1,2) → 48+24=72. All are multiples of 24.
Example 3 — Single Element
$
Input:
hours = [1,2]
›
Output:
0
💡 Note:
1+2=3 is not a multiple of 24, so no valid pairs exist.
Constraints
- 1 ≤ hours.length ≤ 100
- 1 ≤ hours[i] ≤ 109
Visualization
Tap to expand
Understanding the Visualization
1
Input Array
Array of hours [12,12,30,24,24]
2
Find Pairs
Check all pairs where i < j
3
Count Valid
Count pairs that sum to multiples of 24
Key Takeaway
🎯 Key Insight: Use modulo arithmetic to find complementary remainders that sum to 24
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code