Given an array of numbers (length >= 1), remove duplicates in place so that each element appears only at consecutive positions, and return the new length k. The first k elements of the array should hold the deduplicated values; elements past index k - 1 may be left as anything.
Note: this implementation compares adjacent elements only, so it deduplicates runs of consecutive equal values rather than performing a full set-style dedupe.
Input
arr: an array of numbers with length at least 1
Output
The new length after removing consecutive duplicates in place.
Examples
Example 1
Inputarr = [1, 2, 3, 4, 5]
Output5
Example 2
Inputarr = [10, 20]
Output2
Constraints
arr.length >= 1
Must modify arr in place without extra memory.