Problem 60476. Remove Adjacent Pairs
Given an array of integers where adjacent elements may be identical, your task is to remove these adjacent pairs. If removing one pair creates a new pair, continue removing pairs until no more adjacent identical elements remain.
For example, in the array [1,2,2,1,3], the adjacent pair is (2,2). After removing this pair, the resulting array is [1,1,3]. A new pair appears, (1,1). After removing this pair, the resulting array is [3].
Examples:
- Input: [1,2,3,3,2,4,3] Expected Output: [1,4,3]
- Input: [1,2,3,3,2,1] Expected Output: []
- Input: [2,2,2] Expected Output: [2]
- Input: [1,1,2,2,3,3,4,4,5,5] Expected Output: []
- Input: [1,1,1,2,2,3,3,4,4,5,5] Expected Output: [1]
Solution Stats
Problem Comments
-
1 Comment
Christian Schröder
on 9 Jun 2024
Excellent problem again. Please keep 'em coming!
Solution Comments
Show commentsProblem Recent Solvers9
Suggested Problems
-
2815 Solvers
-
407 Solvers
-
What is the distance from point P(x,y) to the line Ax + By + C = 0?
554 Solvers
-
Flip the main diagonal of a matrix
897 Solvers
-
Replace all zeros and NaNs in a matrix with the string 'error'
103 Solvers
More from this Author53
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!