Comment by sokoloff
For campus, we ask very straightforward questions to try to weed out the very lowest of coding fluency at that early stage. (Basically to try to guard against late track changers who haven’t actually coded but know that the SWE market is better than whatever their original interest was.)
If I ask that of a senior candidate, it’s because I got a whiff of “this candidate might not be able to code at all, and I’d like to save us both some time and frustration.”
We ask of every candidate. At least half the time, I wish I'd done so before getting invested in the "experience" portion, when that ends up not actually translating to ability (and believe me, I am trying to help them to succeed)
The beauty is, even a simple exercise answered quickly like "sum of integers" provides ample opportunity to learn a lot about how they think.
Start digging in to testability, requirement changes, etc. Change it to a rolling sum (producing a sequence instead of a single value). Do they use an array or an iterator? Do they output straight to the console, or produce an actual function? Could the numbers come from other sources (database, queue, etc)? What might the tradeoffs be? If there's something they are unfamiliar with, are they quick on the uptake if you explain it? And so on.