Interview Question






Comment hidden because of low score. Click to expand.
16
of 20 vote

public String solution(int A, int B, int C, int D, int E, int F) {
        int temp = 0; Double testNum = 0.0;
        int[] numsArray = new int[]{A,B,C,D,E,F};
        // Sort the Array
        Arrays.sort(numsArray);
        for (int i = 0; i < 6; i++){
            if (numsArray[i] > 5)
                temp++;
            testNum = testNum + numsArray[i]*Math.pow(10.0,5.0-i);
        }
        // Test of high digit count
        if (temp > 3){
            return null;
        }
        // Number is Too Big to be a time
        if ( testNum > 235959){
            return null;
        }
        // Number can be a time, just needs sorting
        if (numsArray[4] > 5){
            temp = numsArray[4];
            numsArray[4] = numsArray[2];
            numsArray[2] = temp;
        }
        if (numsArray[2] > 5){
            temp = numsArray[2];
            numsArray[2] = numsArray[3];
            numsArray[3] = temp;
        }
        if (numsArray[2] > 5){
            temp = numsArray[1];
            numsArray[1] = numsArray[2];
            numsArray[2] = temp;
        }
        if (numsArray[2] > numsArray[4]){
            temp = numsArray[4];
            numsArray[4] = numsArray[2];
            numsArray[2] = temp;
        }
        return ("" + numsArray[0] + numsArray[1] + ":" + numsArray[2] + numsArray[3] + ":" + numsArray[4] + numsArray[5]);
    }

- shauny January 27, 2019 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More