Deduplicate Adjacent
EasyData EngineeringArraySorting
Description
Given an array, collapse each run of consecutive equal values into a single value, preserving order. Non-adjacent repeats are kept.
Examples
Input:
[1,1,2,2,1]Output:
[1,2,1]Explanation:
A run of identical neighbours is reduced to one copy, but a value that reappears later after a change is kept.
Input:
[5,5,5]Output:
[5]Explanation:
A run of identical neighbours is reduced to one copy, but a value that reappears later after a change is kept.
Input:
[1,2,3]Output:
[1,2,3]Explanation:
A run of identical neighbours is reduced to one copy, but a value that reappears later after a change is kept.
Constraints
- •
0 ≤ length ≤ 10⁴