Weave interview question

Leetcode medium question around subarrays.