ByteDance Interview Question

Two coding questions, one easy and one medium