UBS interview question

Leetcode ez question. Java. Sort.