Flexible Finance Interview Question

Leetcode medium question + follow-up