SDE2 coding question on Sorting

I was given a problem to solve and the solution suggested by the interviewer seems to be wrong.

Given : 300GB of dictionary data with key, values as product name and number of reviews given by the customers.

output : Need to sort this data by values and return

condition : The sorting should be done on 1GB RAM machine.

I came up with a Brute-force approach first and then started optimizing it.

The brute-force approach is as follows:
take 1GB data at a time and sort the dictionary and save in a new dictionary. This way all the 300 new dictionaries will contain sorted key, value pairs. Now I had taken 1st key,value pair from the 1st dictionary and compared it with the other 299 dictionaries 1st value and replaced with the minimum, the loop continues with other elements in the dictionaries. I know it is very time consuimg approach but with the given 1GB RAM couldn't think of anything better in that situation.

At the end of the interview I asked the interviewer, how did you solve this problem ?
Interviewer's reply : It can be done with the external sorting
I went to through the external sorting, and surprised that the last step of sorting will be done on 150GB + 150GB data, which is not possible here.

Anybody solved problem before ?

Comments (2)