3418. Count Pairs That Form a Complete Day II
My accepted Python solution to LeetCode problem 3418, Count Pairs That Form a Complete Day II, running in 1073ms.
- Difficulty: Medium
- Python
- Runtime 1073ms
- Memory 69.2MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 1073ms, memory 69.2MB, accepted 2025-12-30.
class Solution:
def countCompleteDayPairs(self, hours: List[int]) -> int:
from collections import defaultdict
# Use hash map to count remainders
remainder_count = defaultdict(int)
count = 0
for h in hours:
rem = h % 24
# Need a pair with remainder such that (rem + other) % 24 == 0
# Other should be (24 - rem) % 24
target = (24 - rem) % 24
count += remainder_count[target]
remainder_count[rem] += 1
return count