7 kyu

Set the Clock

Description:

All clocks can have their times changed, so when a clock is going too fast or slow, the time can be changed to be correct again. Bob has a 24-hour clock (so 2:00 PM will be 14:00 instead), on which there are two buttons -- the H button and the M button, which increase the hour and minute, respectively, by one. Given the list of buttons Bob presses and the starting time, figure out what time Bob set his clock to.

Some details:

  • When the minute reaches 60 it resets to 0 without changing the hour
  • Hours do not have leading zeros, only minutes do
  • The hour for midnight should be 24; 0 is not used as an hour

It is guaranteed that:

  • There are no more than 59 'M's and 23 'H's that Bob presses
  • The time given as the starting time will always be a valid 24-hr time

Examples:

set_clock("9:21", ['M', 'M', 'M', 'M', 'H', 'H', 'M'])                                     => "11:26"
set_clock("16:54", ['M', 'M', 'H', 'M', 'M', 'H', 'H', 'H', 'M', 'H', 'H', 'M', 'H', 'H']) => "24:00"
Puzzles
Fundamentals

Similar Kata:

More By Author:

Check out these other kata created by LogicalX

Stats:

CreatedNov 26, 2020
PublishedNov 26, 2020
Warriors Trained550
Total Skips7
Total Code Submissions1765
Total Times Completed320
Python Completions320
Total Stars6
% of votes with a positive feedback rating86% of 95
Total "Very Satisfied" Votes74
Total "Somewhat Satisfied" Votes16
Total "Not Satisfied" Votes5
Total Rank Assessments22
Average Assessed Rank
7 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
8 kyu
Ad
Contributors
  • LogicalX Avatar
  • ozichukwu Avatar
Ad