Expedia Group interview question

Easy leetcode question using stack