ByteDance interview question

My previous research + coding