Paytm interview question

Self join, Windows function, Logic building