r/CodingForBeginners • • 23h ago

I keep getting stuck coding DP solutions, even when I know the approach. What helped you get past this?

Understanding a DP explanation and writing the Python code still feel like different skills.

A Python learner has watched plenty of tutorials and knows that dynamic programming has different patterns. The sticking point comes at the blank editor: there's a rough idea of what should happen, but turning it into a working implementation is difficult.

Would you step back to smaller Python exercises, work on recursion first, or stay with very simple DP problems? A practice routine that forces an attempt before reading the solution sounds more useful here than another long playlist.

For someone practicing toward technical interviews, real interview questions can supply prompts once the basic Python implementation feels manageable. I'd start with a small enough problem to write and trace the whole thing.

What helped you make the jump from following a solution to writing one yourself?

Disclosure: I operate PracHub.

2 Upvotes

2 comments sorted by

1

u/itlogicpartnersllc 21h ago

what helped me was writing the recurrence in plan english first then translating it into cod start with the base cases solve tiny example by hand and add memoization afterward

1

u/TheUmgawa 14h ago

Can you solve it by hand? I live by my Yoda’s mantra, “If you can solve it by hand, you can solve it in code.” Playing cards often make good simulations of data. I learned this in a Programming Logic and Design class at community college, where we never wrote a single line of executable code, and it got me to unhook my brain from thinking the code is the solution. It isn’t, any more than the words on the page are a story. The code, or the words on the page, are the implementation. The logic is the solution.

So, make a map. It doesn’t have to be a formal flowchart, but it has to involve all of the steps to implement the solution. Imagine going into a maze and trying to get to the center or the exit, or whatever the goal is. When you’re in the maze, it sucks. But, if you can see the maze before entering it, you can write down the directions, which will save a ton of time. This is also why so many writers never finish their novel; they have no idea where they’re going with the plot.

I have never understood why the immediate reaction to reading a prompt is to just start hammering away at the keyboard. It’s like trying to cook a fine meal by throwing all of the ingredients in a pan and hoping it comes out right. It won’t. You have to organize, do prep work, and then you can cook it. The prep work is an example of building a program out of order. It doesn’t matter where you start; only where it ends. But trying to cook without thinking about it first is why so many people struggle with anything fancier than Kraft Mac and Cheese.

Get out a piece of paper, solve the problem, write the implementation.