I can follow coding lessons, but I get stuck when I have to solve a new problem on my own. Sometimes I know I need a loop but can't remember how to write it. How should I practice for interviews?
How do I get better at solving coding problems without memorizing answers?
Answers
Start smaller than interview problems for a bit. Practice counting, summing an array, finding even numbers, and reversing a string in the language you plan to use. Write the code yourself rather than coding along with a lesson.
For a loop, identify the starting value, the condition for continuing, and how the value changes each time. Run through a few iterations on paper, then check whether the code does the same thing. Short, regular practice will give you more chances to use those basics.
Reply to this answer
Before touching syntax, solve a small example as a person. Write down the input, the result you want, and the steps that get you there. Then turn one step at a time into code.
If you need to look at a solution, don't just copy it and move on. Work out what each part does, close it, and try writing your own version. Come back to the problem later and see whether you can explain the approach without looking.
Reply to this answer
It's okay to look up syntax while learning. Try on your own first, then check the docs when you're stuck and finish the exercise yourself. For interview practice, also do some attempts without autocomplete or notes so writing the basics cold feels less unfamiliar.
Reply to this answer
Once the tiny exercises feel manageable, try some easy coding challenges. Don't worry about racing through a huge collection. Take time to understand why an approach works and test it with a few different inputs, including an empty input when that makes sense.
Practicing under a little time pressure can also help, since knowing something at your desk and explaining it in an interview aren't quite the same task.
Reply to this answer
Add your answer
Answers are reviewed before publication.
4t~velourmarker_759:
A debugger or a few log statements can help you see where the actual values stop matching your paper trace.