Pregunta de entrevista de ByteDance

Two coding questions, one easy and one medium