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.
Assuming you do have to remember their order and that the numbers are in the range of 1 to 1,000,000, it would only take 20 bits or 2½ bytes to write each one since 1,000,000 is 0xF4240 in hexadecimal. You'd have to pack them together to not waste any space with this approach, but by doing so it would only take 2.5 * 1,000,000 bytes.
Python: Write 1,000,000 ints to file