FLEXE Interview Question

equivalent to a leetcode - medium.