Whether this is the case quickly becomes apparent by working closely in tandem with the person, e.g. pair programming. It will be obvious within the first few minutes whether the person simply cannot hold a train of thought for as long as the problem requires. As you write, there are concrete ways of addressing this.
On the other hand, it is also obvious when the lack of productivity stems not from a lack of focus but simply not having a mind suited to the job. I’ve seen people focus intently for hours to complete a task that would take most others on the team a few minutes, and not for lack of knowledge or training; their brain simply worked at a much slower speed. There is nothing that can be done to rectify this. These are thus the hardest people to empathetically fire, since you’re basically letting them go for not being smart enough for the job, despite being an extremely diligent worker.