Amazon Interview Question for Software Engineer / Developers

Country: India
Interview Type: In-Person

Comment hidden because of low score. Click to expand.
of 1 vote

I am not sure of the answer as much but this can be done as below:
physical memory = 20GB approx 2^35 addresses
logical memory = 2GB 2^31 addresses
To implement memory management so that the whole physical memory can be accommodated in logical memory on demand paging
We need to divide physical and logical memory into same and fixed size frames and pages respectively.
Size of page = size of frame = size of logical memory/no of pages = size of physical memory/ no of frames
 2^31/x = 2^35 /y
 y/x = 2^35 /2^31
 y/x= 2^4/1
this means for every 16 frames we make in physical memory of size 2^31 each we make one page of same size
To optimize our page size in the range 2^9 to 2^14 bytes
We get y/x = 2^21/2^17 for page size 2^14 bytes

Hence we have now 2^21 frames and 2^17 pages with sizes 2^14 bytes each

Now , logical address of page = page_address_bits(n)+offset_bits(d) => 17 bits+14 bits =31 bits
Each page corresponds to a particular frame in page table so to address that frame is
physical address of frame = frame_address_bits(n)+offset_bits(d) => 21bits+14 bits

- Shweta October 16, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
of 0 votes

To correct you, Question says File is 20GB and RAM is 2GB, so
Physical Memory - 2GB - equal to RAM.
Logical Memory (virtual memory) - Depends on OS/System.

- skum June 22, 2015 | Flag
Comment hidden because of low score. Click to expand.
of 0 vote

I'm not sure 100% what you want, but if you just open a file stream and read in what you need writing the content to the output file (I assume this is what you mean by split) until you find the break point. Then close the file you are writing to and open the next one. No need to do anything special as the OS is handling all the memory management for you.

Then again I could be very confused about what the problem is. Then again I remember when 128 MB of memory was a thing and virtual memory was worth it's weight it gold ;-)

- Anonymous August 11, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
of 0 vote

it kind of depends also on what you want to do with the contents of the file. if you just want to read the file, read only the first few pages(OS memory pages) of the file. While the CPU is reading these pages and working on them, you can use double buffering to get next set of pages. When the third set of pages comes, it replaces the first set of pages, fourth set replaces the second and so on. You can also use triple buffering. if you require non-sequential reading of file, you can adapt a suitable page replacement policy.

- ayush August 12, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
of 0 vote

Please elaborate the problem.

- Dharmendra August 13, 2014 | Flag Reply

Add a Comment

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.


is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More


CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More