Urban Ladder Interview Question

Mysql query optimization