Write an algorithm to find the IDs of two songs whose combined runtime will finish exactly...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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 <-1, -1>. 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. 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 <-1, -1>. 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.
Expert Answer:
Answer rating: 100% (QA)
Python def findsongpairrideDuration songDurations targetduration rideDuration 30 ... View the full answer
Related Book For
Computer Architecture Fundamentals And Principles Of Computer Design
ISBN: 9781032097336
2nd Edition
Authors: Joseph D. Dumas II
Posted Date:
Students also viewed these computer network questions
-
Ticket to Ride is a popular board game that involves connecting cities in a given railroad network. In this assignment you will prototype some potential approaches for creating an AI player for this...
-
Shown here is a list published by Electronics Weekly.com of the top five semiconductor companies in the United States by revenue ($ billions). a. Construct a bar chart to display these data. b....
-
Prom the data in Exercise 13.18a, predict the fundamental vibrational Wave numbers of the deuterium halides.
-
A major storm event was recorded for Little Bear Creek. The incremental rainfall and measured hydrograph data for this storm are provided in Table P2-12 in 1-hr increments. The drainage area for the...
-
The payroll disbursements were for two persons named Ciotty and Ciotti with the same first name and address. The interesting observation is that Ciotty is dated February 28, 2019, or after while...
-
Use the following information to prepare a classified balance sheet for Alpha Co. at the end of 2016. Accounts receivable .....$26,500 Accounts payable ....... 12,200 Cash ............ 20,500 Common...
-
Nina has been with Elora Enterprises for 5 years and is a Customer Service Representative. She earns $2000.00 bi-weekly working 35 hours per week. She does not work any overtime. She has not reached...
-
The figure shows a graph of r as a function of in Cartesian coordinates. Use it to sketch the corresponding polar curve. 2. 14 -1-
-
3. Find the Taylor Series for 3 f(x) = ln(4 + ,x) about x = 0. Show the complete %3D solution.
-
Describe a correlogram. What is its purpose?
-
Briefly explain the following statement: Although long-term bonds are heavily exposed to interest rate risk, short-term T-bills are heavily exposed to reinvestment rate risk. The maturity risk...
-
When should a double exponential smoothing technique be used?
-
Assess the linkages between SHRM and employee relations.
-
List the three goals of a lean system and explain the importance of each.
-
The first transatlantic submarine telegraph cable was laid in 1858, only 14 years after Morses first official message was sent. The line was very slow (it took 16.5 h to send a 96word message from...
-
Problem 2. (0.6 points, 0.2 points for each question) (a) A company turns its inventory 2 times a month. Its months-of-supply = Its days-of-supply = Please show your analysis below: _months. days. (1...
-
How are VLIW architectures similar to superscalar architectures, and how are they different? What are the relative advantages and disadvantages of each approach? In what way can VLIW architectures be...
-
Considering the overall market for all types of computers, which of the following are more commonly found in todays machines: arithmetic pipelines or instruction unit pipelines? Explain why this is...
-
Explain how a dataflow machine avoids the von Neumann bottleneck.
-
What are the purposes of the international capital market?
-
A strong US dollar makes imports cheaper for American consumers, but it also makes American exports less competitive and more expensive on the global market. What are the implications of a strong and...
-
You are the senior accountant for a business that regularly imports spare parts for a range of your products from overseas suppliers. You have been instructed by the CEO to look at ways you can save...
Study smarter with the SolutionInn App