The algorithm is interesting but it’s not really a fair solution because the hash table is doing the real work.
But the context stinks, Whiteboarding is a ridiculous way to evaluate candidates since it adulterates the evaluation with the unreasonable pressure of working under scrutiny. Trying to think while some jerk with an impenetrable accent sniffs and fidgets and offers misleading suggestions. Many, many times I’ve frozen up in these circumstances, been unable to make any progress, then solved it in my head in seconds as I walked back to my car. Three different ways, in fact.
I don’t work onsite anymore, not in these depraved days of open offices and daily scrums, but I nevertheless state on my CV that I will n0t do Whiteboard interviews. Not that it matters; recruiters don’t read resumes. They just run them through ATS and then, ignoring my time zone as much as everything else, call me at 4AM to dees-coss an op-pore-TOO-nee-tee een BFE, and of course it’s onsite.
But that’s OK. They’re “moving forward” with other candidates.