Skip to the content

The recipe's time

Problem

Grandma Rose's stew recipe fills three pages, and every step has its time in the margin: "12:30" to brown the meat, "3:45" to chop the onions. Before starting, Sam wants to know how long the whole thing takes. You get a list of strings (it may be empty). Each one is minutes, a colon and seconds: the minutes have one or more digits and the seconds always two, from 00 to 59. Return the total in that same format, as a string: the minutes with no leading zeros, as many digits as needed (they can go past 59 and past 99), and the seconds always in two digits. With ["12:30", "3:45"] you return "16:15". With ["0:40", "0:25"] you return "1:05": 65 seconds are one minute and 5. The empty list gives "0:00".

Examples

  • Two steps

    ["12:30", "3:45"] → "16:15"

  • A single step

    ["5:07"] → "5:07"

  • The seconds turn into a minute

    ["0:40", "0:25"] → "1:05"

  • A recipe with no steps

    [] → "0:00"

Besides these, the challenge has hidden tests that are revealed when you submit your solution.

You start with this

Python

def total_time(steps):
    pass

JavaScript

function totalTime(steps) {
}
Solve this challenge

It opens in your browser, with the editor and the tests. This challenge is part of the full plan; the O(1) and O(log n) ones are free.

More O(n) challenges

See all challenges →