TikTok Interview Question

A leetcode standard stack problem