TikTok interview question

A leetcode standard stack problem