Remix.run Logo
▲ alexfoo 2 hours ago

> Well I mean so far it's just a warmup exercise. How deep of a discussion can you have about finding the three most common numbers in a list?

It can go surprisingly deep if you add some constraints.

How would you solve this if the input was always small (i.e. somewhere around 20 lines)?

Could you make your solution much simpler if you just had to find the single most common number in a list?

How would your solution change if you had to find the n most common numbers in the list?

How would you solve this if you had finite memory which meant you could only hold a given number of the unique numbers in memory?

a) With no local/disk storage, but the ability to rewind and reprocess the file as many times as you like.

b) With access to local/disk storage large enough to store a file or files with total size around the original input file size.

How would you solve this if you had to process the file as an input stream (i.e. you can't rewind or replay it) and output the answer every n input values? (But there are no memory constraints.)

...

All of the above have different nuances which mean what works for one does not work for another, or is complete overkill, etc.