Beginners struggle with this easy question (zeros within two steps)
HTML-код
- Опубликовано: 5 фев 2025
- Watch me methodically apply my problem-solving process to an easy question. Straightforward problems are great for isolating process issues, because there's no excuse not to get things perfect. Try it yourself first (it should only take a few minutes) and then compare your approach to mine.
My teaching company: watchandcode.com
A lot of teachers introduce solutions as fully-formed and just explain how they work. But they miss the most important part, which is how the solution was discovered and why it's correct.
A key area where my process differs from most is how I spend most of my time thinking about the problem without code. For example, I try to conceptualize the problem and visualize it in various ways. I also explicitly think about correctness as part of the problem-solving process.
Gordon is the best teacher. I
I took this and applied it to the problem I was working on right away by redoing the problem again from scratch. Especially the part where you broke down the problem statement, this step was very actionable. This made a difference in how I rephrased the problem and the improvements trickled down the problem solving process. Improvements on conceptualizing the problem, outlining my strategies and cleaner code. Significant value in this video!
Great video - especially the resistance to code and the importance of developing some abstraction to deeply understand the question!
At one point I describe a "tempting" approach that's worse, but is worth executing for "educational benefit". If you followed up on that and got it to work, let me know.
Great explanation! The rephrasing of the question was very useful. It's tempting to not take the time to think through simple problems like this one.
Yeah it's really interesting how so many people will execute a more difficult, less clear, more error-prone strategy, when there is an obvious one in plain sight. I think it comes from jumping into implementation too soon and fixating on example inputs rather than broadly conceptualizing the problem.
@@GordonZhu, Absolutely agree. I also came up to someone's very complex solutions when I have already solved that with simpler approach. At that time, my imposter syndrome turns on and I feel like I am less skillful engineer as I came up with simpler solution..
Thanks for sharing, Gordon.
It's really helpful to see your process in action and in detail.
I think for many starting with programming there is a temptation to think you can just look at code and absorb what's going on.
Visualising a problem at the beginning, *without* getting preoccupied with the code specifics is super helpful.
Turning a coding problem into a visual puzzle, or riddle, really foregrounds the fact that this is just a problem. Coding/syntax is clearly something best considered after thinking about the problem and potential strategies.
Of course knowing your syntax and the specifics of your language are important, but robust logic and problem solving underpin everything regardless of language. If I concentrate my effort on code but am being fast and loose with problem solving, I know it is a recipe for a syntactically sound but sub-optimal solution.
Ideally I want my logic and my syntax to both be rock-solid, but when I write some code that doesn't work on the first try, it is much easier to find and clean up a syntax error, than untangle what went wrong with my unwieldy and unnecessarily complicated code.
Well said Luke. Did you try executing the "tempting" approach?
Hi Gordon.
I tried both. One approach was quick and painless. The 'tempting' approach I tried for educational purposes, and it was slow and painful. It took a couple of tries and then I got it to work using your tip. It was much tricker to write, to read and to hold in my head. I can see how going down the wrong path could have lead me to more and more unnecessary complications. "....I could convert it to an array, .... store each value counted in an object.... etc" with each avenue potentially making it messier.
It's satisfying to see that if I remember to think first and think carefully and scribble out a visual of what I'm doing, I have a much higher likelihood of arriving at something that will be easier to write, and should therefore easier to read as well.
As always very insightful video. What is interesting, these days I have started regularly solving leetcode problems. And I found this video very helpful. I hope I will take some classes at watchandcode some day.. Thank you very much.
You're welcome @parnasmi. Glad you enjoyed it!
Hi Gordon,
I thought I had solved this problem, but 6 minutes into your video I realized I had misunderstood the question, like this: count the number of *consecutive* 0s next to each 1, within two steps. I didn't notice I had "embellished" the problem description with my own made-up rule, even though I tried to make sure I understood the question and even rephrased it. Man!! What's a way to make sure that doesn't happen, other than always assuming that I'm wrong every step of the way?
Thank you!! Julia
Assuming that you're wrong unless proven otherwise is a good defense. This is similar to the expectations/reality framework I described in our intro course. That framework allows you to become more accurate over time.
Thanks, Gordon! :) @@GordonZhu
Really struggled to solve this problem
Glad you gave it a shot!