Meta interview question

It was a hard question on leetcode