Interview Question
- 4of 6 votes
AnswerGiven six digits, find the earliest valid time that can be displayed on a digital clock (in 24-hour format) using those digits.
- translink604 May 01, 2018
For example, given digits 1, 8, 3, 2, 6, 4 the earliest valid time is "12:36:48". Note that "12 : 34 : 68" is not a valid time.
Write a java method:
class Solution {
public String solution(int A, int B, int C, int D, int E, int F);
}
that, given six integers A, B, C, D, E and F, returns the earliest valid time in "HIT :mm: ss" string format, or "NOT POSSIBLE" if it is not possible to display a valid time using all six integers.
For example, given 1, 8, 3, 2, 6, 4 the function should return "12:36:48".
Given 0, 0, 0, 0, 0, 0, the function should return "00 : 00 : oo". Given 0, 0, 0, 7, 8, 9, the function should return "07:08:09".
Given 2, 4, 5, 9, 5, 9, the function should return "NOT POSSIBLE".
Assume that: • A, B, C, D, E and F are integers within the range [0..9].
Correct answer 1 point
Efficient solution 2 points| Report Duplicate | Flag | PURGE
- shauny January 27, 2019