ByteDance interview question

Two coding questions, one easy and one medium