Sponsored
Use these hints if you're stuck. Try solving on your own first.
Iterate over the array and simulate the described process.
Solve with full IDE support and test cases