What is the most compact way to write 1,000,000 ints (0, 1, 2...) to file using Python without zipping etc? My answer is: 1,000,000 * 3 bytes using struct module, but it seems like interviewer expected another answer...
Edit. Numbers from 1 to 1,000,000 in random order (so transform like 5, 6, 7 -> 5-7 can be applied in rare case). You can use any writing method you know, but the resulting file should have minimum size.
Well, your solution takes three bytes (= 24 bits) per integer. Theoretically, 20 bits are enough (since 2^19 < 1.000.000 < 2^20).
EDIT: Oops, just noticed Neil’s comment stating the same. I’m making this answer CW since it really belongs to him.
Python: Write 1,000,000 ints to file