Here is one more ineresting solution: class Solution: # Time Complexity: O(n) # Space Complexity: O(1) def numPairsDivisibleBy60(self, time: List[int]) -> int: remainder_counts = [0] * 60 count = 0 for t in time: remainder = t % 60 if remainder == 0: count += remainder_counts[0] else: count += remainder_counts[60 - remainder] remainder_counts[remainder] += 1 return count
Here is one more ineresting solution:
class Solution:
# Time Complexity: O(n)
# Space Complexity: O(1)
def numPairsDivisibleBy60(self, time: List[int]) -> int:
remainder_counts = [0] * 60
count = 0
for t in time:
remainder = t % 60
if remainder == 0:
count += remainder_counts[0]
else:
count += remainder_counts[60 - remainder]
remainder_counts[remainder] += 1
return count