Generate unique permutations with duplicates | Meta Interview Question