I've had so many interviews that started strong, great conversation, amazing resume, and then they couldn't write a basic function to implement a straightforward algorithm.
Like, they literally could not write a nested for-loop that worked (in a language of their choice!).
IMO, the solution is apprenticeships/probationary offers. "Try before you buy" goes both ways - it gives the candidate and opportunity to try out the company (how many companies like about their culture, tools, quality, and work/life balance?!).
Alas, it requires the industry to shift to support that model, it's very difficult for companies and candidates to support that model on their own without most other companies doing the same.