HackerEarth interview question

A normal stack-based problem, if you have done competitive programming it would be very easy for you.