Pergunta de entrevista da empresa Akamai

Find the Town Judge problem. Finished early so I got asked a SQL based question (sorting data)