Answered step by step
Verified Expert Solution
Question
1 Approved Answer
6. Whole Minute Dilemma A music player allows users to choose songs to play, but only in pairs and only pairs of songs with
6. Whole Minute Dilemma A music player allows users to choose songs to play, but only in pairs and only pairs of songs with durations that add up to a multiple of 60 seconds (e.g., 60, 120, 180). Given a list of song durations, calculate the total number of different song pairs that can be chosen. Example n = 3 songs = [40, 20, 60] One pair of songs can be chosen whose combined duration is a multiple of a whole minute (40 + 20 = 60) and the return value would be 1. While the third song is a single minute long, songs must be chosen in pairs. Function Description Complete the function playlist in the editor below. playlist has the following parameter(s): int songs[n]: array of integers representing song durations in seconds Returns: int: the number of songs pairs that add up to a multiple of a minute Constraints 1 n 105 1 songs[i] 1000, where 0 si #!/bin/python3... 10 11 12 13 14 15 16 17 18 19 20 21 > V # # Complete the 'playlist' function below. # > if Autocomplete Ready O # The function is expected to return a LONG_INTEGER. # The function accepts INTEGER_ARRAY songs as parameter. # def playlist (songs): name # Write your code here == '__main__':- 1.... I Input Format For Custom Testing Input from stdin will be processed as follows and passed to the function. The first line contains an integer, n, that denotes the number of elements in songs. The next n lines each contain an integer that describes songs[i] and denotes the duration of the th song in seconds. Sample Case 0 Sample Input For Custom Testing STDIN 4 10 50 90 30 2 Sample Output Function STDIN songs [] size n = 4 songs [10, 50, 90, 30] Explanation The first and second songs pair to 60 seconds. The third and fourth songs pair to 120 seconds. No other pairs will satisfy the requirement. 5 Sample Case 1 Sample Input For Custom Testing Function songs [] size n = 5 [30 20. 150. 100, 40] Python 3 1> #!/bin/python3... DH234STON 10 11 12 13 16 14 # The function is expected to return a LONG_INTEGER. 15 # The function accepts INTEGER ARRAY songs as parameter. # 17 18 19 # # Complete the 'playlist' function below. # Autocomplete Ready def playlist (songs): # Write your code here 20 21 > if __name___ Test Results I main Custom Input
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Python version 36 Python program that creates and test the function playlist def playlistsongs Func...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started