Remove duplicates from a sorted array which allows an element to appear at most twice.