Talentd
FleetCode

3986. Number of Elapsed Seconds Between Two Times

Easy82.5% acceptance

You are given two valid times startTime and endTime, each represented as a string in the format "HH:MM:SS".

Return the number of seconds that have elapsed from startTime to endTime.

Example 1:

Input: startTime = "01:00:00", endTime = "01:00:25"

Output: 25

Explanation:

endTime is 25 seconds ahead of startTime.

Example 2:

Input: startTime = "12:34:56", endTime = "13:00:00"

Output: 1504

Explanation:

endTime is 25 minutes and 4 seconds ahead of startTime, which equals 1504 seconds.

Constraints:

  • startTime.length == 8
  • endTime.length == 8
  • startTime and endTime are valid times in the format "HH:MM:SS"
  • 00 <= HH <= 23
  • 00 <= MM <= 59
  • 00 <= SS <= 59
  • endTime is not earlier than startTime

Hints open one at a time

Hint 1

Convert each time into the total number of seconds since 00:00:00.

Hint 2

The answer is the difference between the two converted values.

4:29
Still stuck?Read the written solution, or watch a walkthrough.
Open solution
Loading editor…
1class Solution:
2 def secondsBetweenTimes(self, startTime: str, endTime: str) -> int:
3
Starter codePython 3Spaces: 4
Examples
Input
"01:00:00"
"01:00:25"
Input
"12:34:56"
"13:00:00"
Your code is saved on this device.Solution