CoStar Group Interview Question

Improve this psuedo code and write some SQL