Need Help on interview question

There are ‘n’ friends who bring gifts to a Halloween party and they exchange their gifts and the array of the number of gifts each person receives is given to you. Check if such an arrangement (array) is possible and if it’s possible then, given an arrangement of the same.

1 1 1
Output: 2 3 1

Any help with approach or code ???

Explain output pls…