Interview Question


Country: Canada
Interview Type: In-Person




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

That's NP-complete.

- S O U N D W A V E October 26, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

How can this be NP-complete? If I understood the problem statement correctly then the problem is "easy". If the entire file can fit in memory then the records can be sorted using any standard sorting algorithm. Otherwise the file can still be sorted using any external sorting algorithm. We just have to sort using the second field of each record.

- EOF October 26, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

So pseudopolynomial time alg?

- S O U N D W A V E October 26, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

struct row_struct
{
	char *data; //for saving second colomn
	long pos; // for saving position of row;
}
->Read file
->sort array of above struct with data O(Nlog(N));
->then print sorted rows using pos.

- RAM October 26, 2013 | Flag
Comment hidden because of low score. Click to expand.
-1
of 1 vote

@RAM, what do you mean?
Sort "positions" into the file (line positions) ?
And why char *data for the second/ field (they are just small integers)?

If you are sorting positions of records in the original file, once you sort these structures, you might have to seek all around the file to actually print the results.

- Urik's twin Cookie Monster (dead now) October 29, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Just use any sorting algo to sort based on second character of word...

1. String[] words =readLine().split(",");
2. call method quickSort(words)
3. sort words based on second character like words[i].charAt(1)>words[max].charAt(1)

Time: for eachline O(nlogn)

- siva October 26, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Put all records one-by-one in BSTree and travarse by In-Order.

- Anonymous October 28, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

Y?

- Urik's twin Cookie Monster (dead now) October 29, 2013 | Flag


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