Paytm Interview Question

Self join, Windows function, Logic building