Microsoft interview question

problem solved by using moving window