Sort an Array with Swapping Only with a Special Character

Given an array of length n + 1, containing elements 1..n and a special character 999 , write a function that sorts the array using only swaps with the special character. In other words, you can only use swap operation between a number and the special character 999. In the end, leave the special character at the end.

Example:

For the given input arr = [1, 5, 4, 999, 3, 2], the output array should be arr = [1, 2, 3, 4, 5, 999].

Contributed by Berkan Teber