ByteDance interview question

Random leetcode question, do more practice