use two pointers only