Skip to main content
Back to problems
#3185
Medium Algorithms

Count pairs that form a complete day ii

Array Hash Table Counting
43.6% acceptance
Feb 24, 2026
194
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)
LeetCode
solution.rs
impl Solution {
  pub fn count_complete_day_pairs(hours: Vec<i32>) -> i64 {
    let mut cnt = [0i64; 24];
    let mut result = 0i64;
    for &h in &hours {
      let rem = (h % 24) as usize;
      result += cnt[(24 - rem) % 24];
      cnt[rem] += 1;
    }
    result
  }
}