Link: https://codeforces.com/problemset/problem/1175/B Pre-requisites: Stack (data structure) Image from: GeeksforGeeks