Friday, April 8, 2011

Given a doubly linked list with just 3 numbers 0,1,2 . Sort it

1) Take 2 pointers at starting and at the end of list.
2) traverse list blindly push all the 2s at end of list.---> O(n)
3) move end pointer just before first two and sort normally by two pointer trick in O(n)

No comments: