A security firm audits its night-watch roster. For an audit period, the firm records guardHours[i] — the total number of hours the i-th guard was logged on duty (a guard's logged hours can exceed 24, since a single duty stretch can span more than one rotation). Two guards i and j (i < j) are said to form a clean rotation pair if the sum of their logged hours is exactly a whole number of 24-hour rotations, i.e. (guardHours[i] + guardHours[j]) is evenly divisible by 24.
Given the logged hours of n guards, count how many clean rotation pairs exist among them.
Print a single integer: the number of clean rotation pairs.
Example 1
Input
5 12 12 30 24 24
Expected
2
Explanation
The logged hours are [12, 12, 30, 24, 24]. The pair of two 12-hour guards sums to 24 (divisible by 24), and the pair of two 24-hour guards sums to 48 (also divisible by 24). Every other pair (12+30=42, 12+24=36, 30+24=54) is not divisible by 24. So exactly 2 clean rotation pairs exist, and the output is 2.
Example 2
Input
3 0 24 48
Expected
3
Explanation
The logged hours are [0, 24, 48]. Every pairwise sum (0+24=24, 0+48=48, 24+48=72) is divisible by 24, so all 3 possible pairs are clean rotation pairs, and the output is 3.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →