Alibaba Group interview question

Why do you solve this problem in this way?