Problem 2295 · Medium
Keep a hash map from each value to its position, so each replacement finds its slot in constant time.
Open the interactive visualisation