Skip to content
LC-3185 Medium LeetCode

3185. Count Pairs That Form a Complete Day II

Read the full problem statement on LeetCode.
Difficulty: medium Acceptance: 43% Topics: Array, Hash Table, Counting
View full problem on LeetCode

Reading material

Reference solution (spoiler · python)
# Time:  O(n + 24)
# Space: O(24)

# freq table
class Solution(object):
    def countCompleteDayPairs(self, hours):
        """
        :type hours: List[int]
        :rtype: int
        """
        result = 0
        cnt = [0]*24
        for x in hours:
            result += cnt[-x%24]
            cnt[x%24] += 1
        return result

Solution from kamyu104/LeetCode-Solutions · MIT