Intel Corporation interview question

generic leetcode question about colored balls