Parse a Timestamp
Medium · rating 1100 · strings, implementation
Read a duration in the format HH:MM:SS (each field two digits). Print the total number of seconds.
Editorial
Parse a Timestamp converts HH:MM:SS into a total number of seconds. Split on the colons and combine: hours·3600 + minutes·60 + seconds.
h, m, s = map(int, text.split(':'))
print(h*3600 + m*60 + s)Complexity
Time: O(1). Space: O(1).