Quote:
Originally Posted by well named
I'd originally tried to do the if/else block in the opposite order which doesn't work, and instead of just swapping them I added the variable because I'm a silly person.
This was wrong actually, the order doesn't matter. I must have had some other problem.
Incidentally, this is why I don't like whiteboard problems. I tend to think of some general approach (use a hash to store the first position each character was seen in, keep track of the earliest duplicate...) and then I start writing some code and it doesn't work and I don't quite understand why and then I play with it -- running it a bunch of times -- and then it works. That iterative process works well for me IRL but isn't easy to do at a whiteboard.
Basically I think I have trouble keeping an entire problem in my head, I need the scratch space.