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
Count Pairs That Form Complete DayFind pairs where hours[i] + hours[j] is multiple of 241212302424index 0index 1index 2index 3index 412 + 12 = 24 ✓24 + 24 = 48 ✓Valid pairs found: (0,1) and (3,4)Result: 2 pairs form complete days
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
Asked in
Amazon 35 Microsoft 28 Google 22
34.8K Views
Medium Frequency
~15 min Avg. Time
892 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen