unknown Interview Question for Personnels


Country: India




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

I think the "trick" part of this question is to use the QUEUE operations (enqueue/dequeue) and you are not allowed to iterate through the linked list!
So the solution is that one step in the iteration should read the first-out entry (dequeue), compare and then enqueue it. After all items are examined the queue is in the same state as it was.

- Selmeczy, P├ęter February 14, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

min = queue.head.val
max = queue.head.val
queue.head = queue.head.next
for node in queue
    if node.val > max 
                  max = queue.head
    if node.val < min
                  min = queue.head

- Anonymous February 14, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

In the solution above, to find the max and min, the program has to compare 2n times. as we know, the lower bound of select max and min is (3/2)n-2. So we can reduce the compare times to (3/2)n requiring one more space.
min = queue.head.val
max = queue.head.val
prior.
queue.head = queue.head.next
for node in queue
prior = node.val;
node = node.next;
if(prior>node.val)
{
max=prior?max:prior>max;
....
}
else
{
....
}

- zxyecn February 15, 2012 | Flag Reply


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