Hello Friends,
Recently I faced below interview question.
You have n files in a directory, given their size (in bytes), find k largest sized files.
I gave a minHeap solution with size k, where I can push all file pairs <file_name, size> into the minHeap. In this way, the minHeap will have top k sized files. And finally I pop all k pairs from minHeap and reverse them.
The Time Complexity of this solution is O(n logk) and Space Complexity is O(k).
But the interviewer said that this is not the best optimal solution, but still it is a fine solution.
So I am curious to know what can be most optimal solution of this problem
Please share your views on this.
Thanks in advance