Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package pairs_of_songs_with_total_durations_divisible_by_60

func numPairsDivisibleBy60(time []int) int {
ans, m := 0, [60]int{}
for _, t := range time {
ans += m[(60-t%60)%60]
m[t%60]++
}
return ans
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package pairs_of_songs_with_total_durations_divisible_by_60

import "testing"

type caseType struct {
input []int
expected int
}

func TestNumPairsDivisibleBy60(t *testing.T) {
tests := [...]caseType{
{
input: []int{30, 20, 150, 100, 40},
expected: 3,
},
{
input: []int{60, 60, 60},
expected: 3,
},
}
for _, tc := range tests {
output := numPairsDivisibleBy60(tc.input)
if output != tc.expected {
t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected)
}
}
}