Man, don't despair!

Seriously. I think that you are just doing the wrong interviews. Applying for the next wanna-be-like Google company that asks for stupid riddles (yes, they are damn stupid - and I hate them, because they are totally unrealistic, disconnected from reality, and with a lot of pre-assumptions that in reality never happen) and "how to find the n-th element in a non-sorted set considering that there is a rat jumping up and down every 30 seconds and this has an impact on how the numbers are stored, ... in time O(logN) with space O(1) etc" doesn't say about you or your abilities.

Nothing. At. All!

It only says that you didn't prepare well for that sort of exercises. Can you do better? Maybe, if you [still] find the fun in it, which you don't and it seems you never did. So ditch it! That's not what you wanna do now! You know what you can do? Apply for a job. They ask you to do the codility test? Just ditch them. Don't take s* from anyone that doesn't value you as a human being. A machine can't assess how good you are. Yet. Maybe in 50 years. Not today.

Right now you need to regain trust in yourself, and in order to do so, you might wanna try to start with a company that doesn't ask you to do these shy tests. I saw that some comments here mentioned a github link with some companies not following such madness. Take a look at them. And remember the rule: DON'T even think about starting the online test if all they ask is a riddle. If they are CS questions, why not. If it's a riddle, stop it right away and maybe even tell the company that you won't do it and why - they might want your feedback. Again, this is entirely up to you.

I want you to repeat it in your mind until nausea: these tests don't say anything about yourself! They only say how bad the company is, as they don't value anything else but your ability to solve riddles that they find "smart". So, the question is: do you want to interview with someone that sees the real s that you can do and that you can offer, or someone that likes to assess how good you are with their interviewing process?

Remember: interviewing is broken. Nobody has yet found a way to assess how really good someone is.

Everyone will tell you "oh but you need to know the basics of CS". All it takes is to learn algorithms and data structures then? That's it? Studying a couple of books? That's all CS is about? And that's all an software engineering job is about? I didn't know that. All I know is that it's inconsistent with the large amount of exams I had to take to get my CS degree. Not 1, not 2. Many!

And the funny thing? They even ask "behavioral" questions, thinking they can spot liars or "culturally unfit people", if you are lucky enough to pass the stupid online riddles. You know how easy it is to fake answers to show that you are such a great team player? Or that you are an ambitious person? Unless you have a psychologist with two big balls during the interviews, and even then, you might find the psychopath that knows how to fake answers. That most of the times become managers. Top level ones.

Seriously - don't feel bad. You achieved a lot, you got your damn degree. Don't let these poor people ruin your life - yes, for me they are poor people, and no, I am not sorry. They just don't know how to interview, but as they are big names, or follow the methods dictated by the big names, they feel they are doing the right thing.

Google admitted many times that their interviewing methods are doomed. It's nice to find that type of guy. It's to create a niche of people that feel intelligent, that need to feel smart, that need to have something in common. It creates equality inside the company, because everyone had to go through the same sh, so nobody questions "how come that this guy got hired?". It's a pool of prepackaged types. I hope you don't wanna be one of them, do you?