1. I'd omit the special cases since they're not necessary for correctness. (Unless I had benchmarks and a performance critical application, but interview questions aren't that.) 2.
parseInt
everywhere mixes up parsing and algorithm logic, which is a recipe for bugs in my experience. You could convert once, in makeDict
. 3. Speaking of ++
, I don't like the new version because it looks like it increments dict[num]
followed by a redundant self assignment, and to C programmers, it looks like undefined behavior. You could post on codereview.stackexchange.com for more opinions. — David Eisenstat 5 secs ago