I'm trying to find pairs of songs with durations that add up to whole minutes. Example given song lengths [10, 50, 90, 30]. Calculate the total number of different pairs. I'm expecting a return of 2 since the first and second pair to 60 seconds and the third and fourth songs pair to 120. But I'm instead getting 1 pair.
def pair_with_target_sum(songs, k):
n = len(songs)
count = 0
for i in range(0, n):
for j in range(i + 1, n):
if songs[i] + songs[j] == k:
count += 1
return count
def main():
print(pair_with_target_sum([10, 50, 90, 30], 60))
print(pair_with_target_sum([30, 20, 150, 100, 40], 60))
main()