Quantiphi interview question

Windows function in Sql and puzzle