Consider using something like interviewing.io to practice interviews with real people that can give you feedback in real-time on how you're doing. Some other people in this thread have offered some other choices, like HackerRank and Code Kata and so on. All good choices for practicing algorithms. Becoming good at interviewing for technical positions is a TOTALLY different skill set than being a good programmer, so just keep practicing and eventually you'll get better.
Once you're more confident, consider using something like Triplebyte or interviewing.io to do your tech challenges and hopefully skip past some of the earlier tech challenges.
For what it's worth, as a hiring manager I would also say that, generally speaking, I'm not interested in whether you got the "correct" answer in 45 minutes, and I'm certainly not interested in perfection in 45 minutes. Don't worry about being perfect. Just worry about being competent. I'm far more interested in the bigger picture. Things like:
1) Can you write code in the first place? The basics should be easy for you.
2) Are you familiar with the language you're writing? You shouldn't have to look up how to sort an array or how to declare a function, for example, and your code should be clean and readable.
3) Can you properly assess the problem and begin working on a solution? Take a moment to think about it. Ask follow-up questions if necessary. I always try to repeat the challenge back in my own words, just to make sure I understand what's expected.
4) Is your solution heading in the right direction? If not, you either don't know what you're doing or I didn't explain the challenge well enough.
5) Can you identify and fix edge cases? Usually the problem I give you will have some reasonably obvious edge-cases, like the popular FizzBuzz test has.
Trust me. As an interviewer, I know you're nervous. I don't expect perfection. I expect thoughtfulness, progress, and adaptability. I expect you to think through a problem, make progress toward a solution, and be able to make changes as necessary to fix edge cases and unexpected problems. That's all. (ha.)
IMO, if your interviewer is fixated on whether it's "perfect" or whether you got the exact right answer, they're not good interviewers and perhaps you shouldn't want to work with them in the first place. In fact, an ideal programming challenge should have multiple solutions (e.g., there are many ways to sort a list). The challenge should be more about figuring out how you think than whether you can add 2+2.
Also, keep in mind that the interview works both ways: you should be interviewing them just as much as they are interviewing you. Every question you're being asked is a question you can ask them. If they don't think you're doing a good job, they won't hire you, and if you don't think they're doing a good job, you don't have to work there. Keep in mind that the bare minimum for a programming job is... programming. If that's all they focus on during an interview, they're missing out on everything else you can bring to the table. Imagine if the only question they asked truck drivers was "Can you drive?" or the only question they ask a journalist is "Can you write?"
Good luck!