Fanatics interview question

variation of overlapping problem and one array question medium