Write code that counts lines in a file under different constraints (memory, disk space, in or out of order, etc)

The name of the picture


Write code that counts lines in a file under different constraints (memory, disk space, in or out of order, etc)



In case of memory constraint, I think variation of external sort will work. What are other options. Also how to deal with disk space constraint? Does it hint towards multiple nodes and map-reduce?





have you tried something, if yes show your code, so that you could get better answer
– Gautam Rai
Jul 15 at 14:21





Counting lines in a file doesn't require sorting anything. It also doesn't require more memory than a byte buffer for detecting a newline character, an integer (or long), and a file handle
– cricket_007
Jul 15 at 14:25







I didn't mean we need sorting, I meant to detect new line character, we need to file in memory. If file is too large to fit in memory, we can split it and count the lines in each split like we do in external sort. I might be wrong. This is an interview question I came across on internet. I have not written any code. I was just thinking about the possible solutions.
– priyankaC
7 mins ago









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Arduino Mega cannot recieve any sketches, stk500_recv() programmer is not responding

Visual Studio Code: How to configure includePath for better IntelliSense results

C++ virtual function: Base class function is called instead of derived