If , then
. So, we keep track how many times we have seen
. While considering
, if we have seen
before say
times, then we have
pairs with
as the second element.
Time: . Since there are only
different remainders
, space:
.
class Solution:
def numPairsDivisibleBy60(self, time: List[int]) -> int:
pair_count = 0
seen = {}
for d in time:
neg_d_mod = -d % 60
pair_count += seen.get(neg_d_mod, 0)
d_mod = d % 60
seen[d_mod] = seen.get(d_mod, 0) + 1
return pair_count
Leave a comment