Question: Given four digits, find the maximum valid time that can be displayed on a digital clock (in 24-hour format) using those digits. For example, given

 Given four digits, find the maximum valid time that can be

Given four digits, find the maximum valid time that can be displayed on a digital clock (in 24-hour format) using those digits. For example, given digits 1, 8, 3, 2 the maximum valid time is "23:18". Note that "28:31" is not a valid time. Write a function: string MaxTime(int A, int B, int C, int D); that, given four integers A, B, C, D, returns the maximum valid time in string format "HH:MM" or "NOT POSSIBLE" if it is not possible to display a valid time. Examples: given 1, 8, 3, 2, the function MaxTime shoud return "23:18". Given 2, 4, 0, 0 the function should return "20:40". Given 3, 0, 7, 0 the function should return "07:30" Given 9, 1, 9, 7 the function should return "NOT POSSIBLE". Since there is no possible valid time. Assume that: A, B, C, D are integers with in the range [0..9] In your solution, focus on correctness as well as the performance of your solution. Try to achieve O(n) if possible rather than O(n^2) solution. The format of a date needs to be changed in the following manner: 1 st Mar 1984 => 1984-03-01 Write a function 'ReformatDate' which will take the input String and returns the new format of the string. String ReformatDate(String oldDate); Example: 1st Mar 1984 => 1984-03-01 2nd Feb 2013 =>2013-02-02 15th Apr 1840 => 1840-04-15 The 'Day' may equal any one of the following values: 1st, 2nd, 3rd, 4th, 5th, 6th, 7th, 8th, 9th, ..... 29th, 30th, 31st The 'Month' may equal any one of the following values: Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec The Year will always be represented by 4 digits and may equal anything between 1900 and 2100, both inclusive. Your Task is to format the given list of dates in to the following format: YYYY-MM-DD Where: YYYY represents the year in 4 digits MM represents the year in 2 digits DD represents the day in 2 digits

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!