ZTE interview question

One problem from the leetcode.