By reading articles, blogs, documents, or watching videos, you can become familiar with a topic's concepts before attempting to solve it.
Always try to write the code's algorithm or pseudocode before implementing them.
Try solving puzzles to improve your thinking and problem-solving skills.
Always start with simple queries and work your way up to more complicated ones to balance out the levels.
To come up with new logic and optimize your code, try talking through answers to difficult problems with other programmers.