traverse from small to big and from big to small

two pointers