Question: Write an algorithm to find the IDs of two songs whose combined runtime will finish exactly 30 seconds before the bus arrives, keeping the

Write an algorithm to find the IDs of two songs whose combined runtime will finish exactly 30 seconds before

Write an algorithm to find the IDs of two songs whose combined runtime will finish exactly 30 seconds before the bus arrives, keeping the original order. Input The input to the function/method consists of two arguments - rideDuration, an integer representing the duration of the ride in seconds; songDurations, a list of integers representing the duration of the songs. Output Return a pair of integers representing the IDs of two songs whose combined runtime will finish exactly 30 seconds before the rider reaches their stop. If no such pair is possible, return a pair with . Constraints 0 songDurations[i] 1001 0 i < number of songs Example Input: rideDuration = 90 songDurations = [1, 10, 25, 35, 60] Output: [2,3] Explanation: During the ride duration of 90 seconds, the rider listens to the third and fourth songs (2nd and 3rd index, respectively) which end exactly 30 seconds before the bus arrives at their stop. If two songs have the same duration, select the option with the lowest index.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Python def findsongpairrideDuration songDurations targetduration rideDuration 30 ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Computer Network Questions!