Pergunta de entrevista da empresa Wish

two leetcode medium, not followups due to no time.