by drd93 · 11y ago · 0 comments
bin(x ^ (x >> 1))
Most often interviewers get quite irritated if interviewer comes up with a much simplier and a faster solution than what was intended.Coming up with an unusual solution should be a win, though it's of course not required.
Also, in some cases I might ask a slightly harder follow-up where the shortcut doesn't work.