Sonatus Interview Question

a tricky Leetcode medium question