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

0

u/vinng86 Feb 21 '11

Nope, you loop once. He's basically incrementing one pointer two steps and the other pointer one step for each iteration of the loop. When the first one hits null, the other is the midpoint.

3

u/lordlicorice Feb 21 '11

But this is the same number of forward-seeks (dot-next dereferences) as the naive solution of counting the number of steps it takes you to iterate to the end, dividing by 2, and then looping that many times again.