I relate to this. Turns out it was undiagnosed ADHD for me.
I can focus very well in interviews or exams. They are even fun for me. But when I get the job and I don't have any concrete deadline, it's hard to focus for me and "get things done". Which ends up me thinking I am not good enough and falling into depression again. I can perform when I absolutely have to, but I never figured out how I can make it work outside those environments.