Autodesk Interview Question

solve 1 leetcode medium level question