Autodesk interview question

solve 1 leetcode medium level question