It is a tough call to make. It comes with experience as to how much planning and brainstorming is needed to solve a problem and write the code to solve it. It is one of the primary reasons why just coders do not exist, but exists a big system of project management and system architects. They would generally give guidance to the overall flow of solving the bigger problems and tackle pipeline issues - concept to reality.
On a microscale, it mostly boils down to experience. Where most junior developers would scratch their heads, the senior devs can sail through smoothly. Sometimes, it makes sense to take time out review code and plan it out, sometimes it makes sense to get that big cup of coffee and start the coding grind.
One should focus on strengthening their skills to identify and solve problems and build an efficient system for the same. I personally keep a whiteboard handy to my seating area. I write my problems out, and start by process of elimination for solutions not feasible.