Citadel interview question

It was a leetcode medium problem