[1]: https://www.amazon.com/Cracking-Coding-Interview-Programming...
[2]: https://www.amazon.com/Algorithms-Parts-1-4-Fundamentals-Str...
[3]: https://www.amazon.com/Algorithms-Part-Graph-3rd-Pt-5/dp/020...
[4]: https://www.amazon.com/Algorithm-Design-Manual-Steven-Skiena...
If you want to take that approach, and say "f%!# it, I'm going to buckle down and work my ass off so I do get the job next time" there are a few concrete steps you can take.
1. Find, read, and do the exercises in two or three of the various popular books on "programming interviews". I'm thinking of books like Cracking the Coding Interview[1], Programming Interviews Exposed[2], Ace the Programming Interview[3], etc.
2. The companies you mentioned are well known for asking lots of detailed questions on fundamental computer sciences concepts. If doing "big o" analysis and talking about algorithms in detail isn't your forte, get a couple of good Algorithms course books and go through them. Personally, I'm a fan of the Robert Sedgwick books[4][5][6][7], and the CLR[8] book is a standard in this area.
3. Look over the many various articles / blogs / etc. written about preparing for Google interviews.
https://www.google.com/search?q=google+interview+preparation
I have never applied to Google myself, so I can't speak to that from first-hand experience, but this Steve Yegge blog post always struck me as being excellent:
http://steve-yegge.blogspot.com/2008/03/get-that-job-at-goog...
4. Take as many interesting Coursera, EdX, Udemy, etc. courses as you can find time for.
5. Write code any chance you can. Get involved in, or start, an open source project (or two). Volunteer to code for a non-profit / charity or something in your area. Write an app for yourself, to fill a need of your own.
6. Make sure you broaden your horizons and challenge yourself. If you've always written, say, Java or C++ or Ruby code, then make an effort to learn Go, or Erlang or Haskell or Prolog.
All of that said, as I've gotten older, I probably feel a little bit less of the "I'll show you!" thing. I've developed more of a stoic approach, and almost a bit of a zen mindset. There's a lot to be said for a sort of calm, peaceful acceptance of things, even when they are negative. There's a lot more one could say about this, but I don't want to get too philosophical here. I'll just point out that you applied to two... TWO.... companies. Out of like a BILLION possible companies you could work for. Ok, maybe not a billion, but certainly millions, or thousands, depending on where you live and your willingness / ability to travel.
My point is, don't put too much weight on what happened with Google or Amazon. The whole "dream companies" thing is a crock of shit, IMO, looking back on it with hindsight. I've worked for two companies in my career that I once thought of as my "dream" destinations, and neither experience was anything special (neither was bad either), and not worth getting all worked up over.
Final last bits of advice.
1. Read Nietzsche
2. Read Ayn Rand
3. Get drunk
4. Listen to some Queensryche
5. Profit???
[1]: http://www.amazon.com/Cracking-Coding-Interview-Programming-...
[2]: http://www.amazon.com/Programming-Interviews-Exposed-Secrets...
[3]: http://www.amazon.com/Ace-Programming-Interview-Questions-An...
[4]: http://www.amazon.com/Algorithms-Java-Parts-1-4-Pts-1-4/dp/0...
[5]: http://www.amazon.com/Algorithms-Java-Part-Graph-Edition/dp/...
[6]: http://www.amazon.com/Algorithms-Parts-1-4-Fundamentals-Stru...
[7]: http://www.amazon.com/Algorithms-Part-Graph-Edition-Pt-5/dp/...
[8]: http://www.amazon.com/Introduction-Algorithms-Edition-Thomas...
You'll also get a chance to learn C++ as you go through it.