YLD interview question

Technical question was building a algorithm that is roughtly medium on leetcode