Urban Ladder Interview Question

Time complexity problems