Interview Question






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

This is Amazon 1st round

- Anonymous March 13, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

get_line(n)

count (n-1) '\n', and put all characters into slot1 until you reach another '\n'. return the slot1.

you don't need other buffers. or I missed something here?

- Anonymous March 13, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

My take on this is: Lets say we need to reach line 77 [ i.e 77 is input line #].
Given, constant buffer can store only 10 lines. Other condition is that reading is only once => If sequential reading is ruled out. Reading is only one time and data comes in batch of ten lines.

My understanding is that we need to choose a batch where line 77 comes in as input.


So, in order to read line 77, We need to fetch batch # = 77 / (input capacity of buffer) = 77/10 = 7

i.e from the text file, leave first six batches [or first 7 blocks or 70 lines] and read in lines 71 - 80.

Now once buffer is filled, go to line 77%10.

In this way given line is reached in 2 steps.

Any other views are welcome.

- cirus March 15, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

u r answer works perfectly well.. can we have a counter =0.. for every \n counter increases by 1. we dont have to buffer... when counter = 77-1, then reach for for the incoming sentence and store it til u see \n... process it

- clrs March 24, 2010 | Flag


Add a Comment
Name:

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

Books

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

Videos

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