# LC 3185. Count Pairs That Form a Complete Day II ### [Problem link](https://leetcode.com/problems/count-pairs-that-form-a-complete-day-ii/) ###### tags: `leedcode` `medium` `c++` Given an integer array <code>hours</code> representing times in **hours** , return an integer denoting the number of pairs <code>i</code>, <code>j</code> where <code>i < j</code> and <code>hours[i] + hours[j]</code> 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. **Example 1:** <div class="example-block"> Input: <span class="example-io">hours = [12,12,30,24,24] Output: <span class="example-io">2 Explanation: The pairs of indices that form a complete day are <code>(0, 1)</code> and <code>(3, 4)</code>. **Example 2:** <div class="example-block"> Input: <span class="example-io">hours = [72,48,24,3] Output: <span class="example-io">3 Explanation: The pairs of indices that form a complete day are <code>(0, 1)</code>, <code>(0, 2)</code>, and <code>(1, 2)</code>. **Constraints:** - <code>1 <= hours.length <= 5 * 10<sup>5</sup></code> - <code>1 <= hours[i] <= 10<sup>9</sup></code> ## Solution 1 #### C++ ```cpp= class Solution { public: long long countCompleteDayPairs(vector<int>& hours) { long long res = 0; unordered_map<int, int> umap; for (int& hour: hours) { int tmp = hour % 24; if (tmp == 0) { res += umap[0]; } else { res += umap[24 - tmp]; } umap[tmp]++; } return res; } }; ``` >### Complexity >| | Time Complexity | Space Complexity | >| ----------- | --------------- | ---------------- | >| Solution 1 | O(n) | O(n) | ## Note x