GSK interview question

Instead of sql forced me to do Python given a problem to debugg. How we can improve code it’s about sliding window and nested loops