Interview Question


Country: India
Interview Type: Written Test




Comment hidden because of low score. Click to expand.
0
of 0 vote

Assuming that interviewer wanted your own implementation of compare function.

Write your own sort function, with function to compare two strings.. Sort the first name and then last name.. Now print last name and then last name

- Pradeep Kashyap June 29, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Correction.. * print last name first and then the first name.

- Pradeep Kashyap June 29, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

thanks for ur answer...but i didn't understand where i have to correct dt one...in test using comparator have implemented...but i don't know whether it is correct or not???/

- Muni June 29, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

public int[] merge(int a1[], int a2[]) {
        int[] a3 = new int[a1.length + a2.length];

        int k = 0;
        int i = 0, j = 0;
        k = 0;

        while (i < a1.length && j < a2.length) {
            if (a1[i] < a2[j]) {
                a3[k] = a1[i];
                i++;
            } else {
                a3[k] = a2[j];
                j++;
            }
            k++;
        }
        while (i < a1.length) {
            a3[k] = a1[i];
            k++;
            i++;
        }
        while (j < a2.length) {
            a3[k] = a2[j];
            k++;
            j++;
        }

        return a3;
    }

- Jas June 29, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Please ignore . wrong window.

- Jas June 29, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

You can use charAt(index) and convert it to get the ASCII equivalent and then compare it .

- Jas June 29, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Radix sort?

- AlgoAlgae July 01, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

For comparing strings
-> One way is to convert into ASCII, (int)(s.charAt(i)) will give ascii value.
-> Use Tree Set and interchange words

- prashanthreddy.mtech July 02, 2014 | 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