ByteDance interview question

1 leetcode medium, 1 leetcode hard