Interview Question


Country: India




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

If the metadata of the files don't fit on memory I would use using external sorting. You can split the metadata of the 40 million files on chunks that fit on memory and that you can sort. Once all the files are sorted by date you can start transferring them.
If the metadata for all the files can be fit on memory I would use a min heap to get the files in order.
The cost temporal cost for both is approaches is nlogn but the heap approach takes less overhead

- Fernando June 13, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1. Sorting can be done by the OS itself and the result can be stored in an Array

2. As Fernando mentioned ... a Heap could be used. But the issue is ... that for 40,000,000. The value of nlogn would be very high.

3. We could use a hashmap with 'n' buckets, each bucket with increasing order of date.
Each bucket can then have a linked list, with items in sorted order.

Complexity should be n, considering a good hashing technique.

- deep.kulshreshtha July 02, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

Do not do it. A much better option is to store the list of files, in sorted order ( oldest file first ) in another file, and then iterate over that.

ls -1t <directory>

- NoOne June 12, 2017 | 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