Given a String. You have to convert the given time i,e, 12hours format to 24 hours format.
First line contains a string.
Print the resultant time in 24 hours format.
Step-i) get the length of the given string
Step-ii) create a empty string new_time
Step-iii) if last second character of the string is P go to next step else go to vii
Step-iv) get the hour part from the string
Step-v) if hours equal to 12 append 00 to new_time and copy the rest of the string
Step-vi) else copy the entire string and return the time
Step-vii) get the hours part from the string
Step-viii) add 12 to the hours part and append to the new_time
Step-ix) add rest of the string as it is to the new_time
Step-x)return the string
Time Complexity : O(1)
Space Complexity: O(1)
Let us know if you can come up with a better approach, mail us at firstname.lastname@example.org Your approach will be reviewed and posted with credits to you.