ABCXYZ interview question

several window functions in SQL with bit complex queries. Spark performance tuning