I'm just saying that writing a small function that has to be perfectly correct is a very different task from from writing a small web app where the space of possible solutions is incredibly large.
LLMs don't have perfect recall, so it has to reconstructtthe answer from the information it retained from training. Your example is like asking it math problems: unless it had both seen and retained the specific one you've asked it, it can't answer correctly because doesn't have the capability to reason about the problem and solve it. But something like writing a web app is closer to writing a story, where each next block it spits out doesn't have to be exactly correct, it just has to get the job done.
As for leetcode, I guess it depends on your field, but my logic is this: if I came to an interview and was told to write a microservice that receives a POSTed file, extracts some data and puts it in a DB, that's a solid work-relevant skill test. But if they asked to to write some interpolation functions, I'd consider that a leetcode interview - closer to math than programming, not a good indicator of job ability, not representative of the kind of work I'll be doing.