Don't beat yourself up. The first question you were given was quite difficult. Although, I can't say anything about the second question, the elevator question, since you haven't given us enough details about that one.
How to improve myself at technical coding interviews?
You practice with Pramp. That's the correct answer to your question. It's a site where programming job hunters take turns interviewing each other over real-time video conferencing and with a shared code editor.
You select which language(s) and a few categories you want to be interviewed on. You select a few time slots where you have an hour free. Pramp supplies one question (for you to ask the other person), plus the hints (if he gets stuck) and the answer. And then Pramp notifies you when it found you a match for your appointment.
If the person flakes on you for your virtual practice interview. The next time he wants an appointment, Pramp will match that person with another person who flaked on a previous interview. But if you don't flake on anyone, Pramp will make sure to keep on matching you with people who usually do not flake on their practice interviews.
So you interview the other job-hunter for 30 minutes with the question that was given to you for that purpose. After that, he interviews you with the question that was given to him for you. The questions are very good and difficult given the time constraint. If a question seems too easy, it can happen, but don't be mislead, that's usually because they expect a very thorough answer from you. Then after each interview is over, the interviewer fills out a small evaluation form, which you will see. But of course, he probably also gave you some good verbal feedback during the interview, assuming you both had extra time.
One part I absolutely love about this is that you get to experience interviews from both sides, so you get a real good idea of what your competition might be like. And you will interview programmers that are below your level and some that are above your level.
You'll start seeing flaws in the way some programmers interview, that you will also recognize in yourself to some degree. For instance, you mentioned thinking. Everybody thinks. Some people need more time to think. Some people need less. But some people have trained themselves to talk out loud while they're thinking and describing their thinking process as well. And some others follow the thinking process described by Gayle McDowell in her book Cracking The Coding Interview, so they're not thinking as much, they're going through a mental checklist which makes it easier for them to think about other things, but which makes it easier for them to describe out loud what they're personally thinking about as well.
Disclaimer: I'm not affiliated with Pramp in any way. And right now, I still don't use that site very much, because it is still a little too tough for my level. I just think that they give you the most realistic simulation of what a remote technical interview can be like.
Another thing you can probably do is post a free ad on craigslist, or go to meetups related to technical coding interviews (or related to your field), and find other real live job hunters to practice with. If you're in the US, I assume you'll have free time-limited access to small conference rooms with whiteboards inside of public libraries, or that you'll be able to get access to a place with whiteboards/blackboards that you'll be able to use. Since a portion of your interviews will include using the whiteboard, pairing up with someone and practicing those kinds of interviews with that person should become a part of your plan.