Meta Interview Question

It was a hard question on leetcode