Pregunta de entrevista de Amazon

Question 1: Based on prefix-sum, sliding window. Question 2: Based on Graphs.