Wisk interview question

complete algorithm equivalent to Leetcode hard