Why should an interview question reward you/require you to remember this? If I actually had to solve a real-world problem similar to this, I would google it, see a solution that iterated through the characters with a for loop and go “oh yeah, I forgot you could do that. Duh.” Why am I not allowed to google dumb things? On most days, my brain is focused on high-level abstractions that tie together two or more tools via disparate APIs, why the hell should I remember or think about for loops?
Consider that when athletes are scouted, they are usually not asked to play in a full game of their sport. But instead certain stats like 'how fast can he run 100m' and 'how high can he jump' are used.
Sure, in a real game you will never run 100m in a straight line on asphalt--but the speed at which one runs 100m in a straight line is a good proxy for how fast one can maneuver during real play.
Sometimes analogies are not really meant to be perfect, but just simpler methods of communicating information.
Teams rarely sign players based solely on measures like this, and those that do frequently regret it.
Additionally, the nature of contracts in professional sports are very different from regular employment. Players are cut or traded frequently, often find themselves on very team-friendly deals when unproven, and are granted employment in time-limited blocks.
The general point I am making is: these are not trying to measure actual job tasks, but instead measuring something that (they hope) is closely related to, or correlated with one's ability to perform the job. The idea is that if one can do these sorts of problems, one can probably do the actual job at hand.
This is a claim about the intentions behind these practices.
Intentions aside, the whole point of this perennially recurring discourse is about effectiveness — that certain overused methods of filtering job candidates are ineffective on their own terms — and negative side effects — that they're biased against people with non-traditional / from underrepresented backgrounds.