3 ms·
Yes it is, and it wouldn't fail my algorithm: a -> not in set -> add a (a) b -> not in set -> add b (ab) c -> not in set -> add c (abc) b -> i
by loup-vaillant 5y ago
Yes it is, and it wouldn't fail my algorithm:
a -> not in set -> add a (a)
b -> not in set -> add b (ab)
c -> not in set -> add c (abc)
b -> in set -> remove b (ac)
a -> in set -> remove a (c)
Set has 1 <= 1 element -> return OK
(Of course, "aabcb" would return yes as well, but that's the whole point: we're not asking whether a string is a palindrome, but whether any one of its permutations is.)