Add Minutes on Clock
Python
Medium
2 views
Problem Description
Time is provided as hour (0-23) and minute (0-59). Also an integer k (can be big) is provided. Add k minutes to the time and output the new time in HH:MM format.
Input Format
One line: hh mm k.
Output Format
One time string HH:MM.
Official Solution
import sys
p=sys.stdin.read().strip().split()
if not p: sys.exit(0)
h=int(p[0]); m=int(p[1]); k=int(p[2])
t=h*60+m
nt=(t+k)%(24*60)
hh=nt//60
mm=nt%60
sys.stdout.write(f'{hh:02d}:{mm:02d}')
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!