CoStar Group interview question

Improve this psuedo code and write some SQL