Airbnb Interview Question

balanced brackets, shortest flight path