A Google Interviewing Story
A Google Interviewing Story
If you want to take advantage of having a limited range of possible characters, just use a bit vector. If you're limited to ASCII then you only need 16 bytes to track them all. Less if you're limited to printable characters.
It would be fun to discuss the prime number version in a sort of "how would this work and why would it be terrible?" way, but if I had an interviewer present it as a way to "do better" I'd have to seriously reconsider if I'd actually want the job.
The prime number thing is obviously bad for this problem, since the giant number would grow arbitrarily large and you'd have to do a bunch of expensive division operations. But it's out of the standard box enough to suggest to the interviewer you are a curious sort who likes to think about novel data structures. At any rate, I got the job.
Hehe. Very funny!