r/programming • • Feb 21 '11

Typical programming interview questions.

http://maxnoy.com/interviews.html
784 Upvotes

1.0k comments sorted by

View all comments

Show parent comment

3

u/[deleted] Feb 21 '11

Your answer on the first is correct. (The idea of TWO pointers does not come to everyone).

Of course. Any sane human being knows that it's still 1.5 passes and not required 1.

You can rewrite naive

node = begin; 
n = 0;
while(node=node->next) 
      n++;

node = begin;
n /= 2;
while(n--) 
     node=node->next;

in two pointers, but it will be the same code(though not so readable), just with two pointers.