Is that what you really end up testing though? As parent mentioned this can be broken by simply memorising, so are you sure the candidate is a good problem solver or are they just good parrots?
So I think it's actually evolved into a weird sort of test of conscientiousness. Originally the idea was probably that we will test people's abstract problem solving skills. Can they come up with a solution on the fly? Ok, now can they figure out any clever optimizations?
But at this point it is sort of expected that if you are interviewing with a FAANG you will be getting these sorts of questions (and they tell you that up front), so it becomes a sort of test of "is this person willing to spend 10 hours preparing for an interview"?
Yeah I suspect this is the case, the original intention and structure was solid but it's been progressively shifted into that FAANG space. I think the only solution is probably a question tailor made to the company interviewing, that doesn't rely on leetcode-style approaches to solve.
I’ve had interviewers ask about cycle detection in a linked list. The answer was of course the classic tortoise and hare algorithm. Which took ~15 years to come up with, and was found by a Turing award winner.
Anybody who claimed they “came up with the algorithm themselves” in a few minutes in an interview is a liar, and anyone who takes them at their word is a fool.