#3184
Easy Algorithms Count pairs that form a complete day i
Array Hash Table Counting
78.0% acceptance
Feb 24, 2026
162
12
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.
Solution
Rust
Time O(n)
Space O(1)
impl Solution {
pub fn count_complete_day_pairs(hours: Vec<i32>) -> i32 {
let mut cnt = [0i32; 24];
let mut result = 0;
for &h in &hours {
let rem = (h % 24) as usize;
result += cnt[(24 - rem) % 24];
cnt[rem] += 1;
}
result
}
}