First of all you are doing great, Keep it up...
So, If you are facing a lot of demotivation while not getting your code running perfectly.
Here are some tips that you can think out of it.
1. You can set a goal of doing 3-Easy Question a day for a week. Then Gradually increase
the number of questions per day and when you are much comfortable with easy questions
then switch to medium level questions.
2. If you are facing difficulty in a particular topic i.e. Pointer, Linked-list, Tree, DP...
So please go through the courses provided it will help you a lot in increasing your potential.
3. First try out brute force approach for solving the question and when its perfectly
running then go to discuss and see the optimized approach and make your logic more strong.
4. Don't feel useless or demotivating, It's normal you will gradually improve your coding
skills and logic building. Just do coding consistently 2-3 Q/day.