Intuit interview question

Leetcode hard question