Skip to content

Latest commit

 

History

History

1010-PairsofSongsWithTotalDurationsDivisibleby60

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

Pairs of Songs With Total Durations Divisible by 60

Problem can be found in here!

Solution: Hash Table

def numPairsDivisibleBy60(songs: List[int]) -> int:
    remainders = defaultdict(int)
    number_of_pairs, divisor = 0, 60

    for time in songs:
        if time % divisor == 0:
            number_of_pairs += remainders[0]
        else:
            number_of_pairs += remainders[divisor-time % divisor]
        remainders[time % divisor] += 1

    return number_of_pairs

Time Complexity: O(n), Space Complexity: O(1)