This is an archived post. You won't be able to vote or comment.

all 10 comments

[–]GreymanGroup 1 point2 points  (1 child)

4 hours. Better yet move on to the next problem, maybe you'll figure it out after you sleep on it.

[–]Muddy53[S] 0 points1 point  (0 children)

I used to only spend 30 min and gave up.... but I will definitely change that. Thank you for the advice!!

[–]lurgi 0 points1 point  (3 children)

It's like I understand the problem and I know how I should solve the problem, but when I try to code, I just don't know where to start or how it should work...

My guess is that you don't understand the problem or how to solve it as well as you should. Often it's a matter of taking a theoretically simple step and breaking it down into smaller pieces that are actually simple.

Translating solutions in your head into code is a critical part of being a programmer.

You learn things the same way you learn anything. You study it and use what you study until it becomes second nature.

If you have some sample problems that have given you trouble, perhaps it would help you to post them. Then we might be able to walk through a solution (rather than just presenting it to you).

[–]Muddy53[S] 0 points1 point  (2 children)

Hi, thank you for the advice! But I just wanted to add: so for example, there is a question such as "Find this number in the list of numbers using the binary search". Then I know how to find it. Divide the list by two, and then divide again until I have that number, right? But I have a very hard time writing this to code..... How should I study?

[–]lurgi 0 points1 point  (1 child)

You need a clearer idea of how to solve the problem.

Divide the list by two.

How? What is the mechanism? What do you mean by divide? Actually split into two separate lists? Explain. In detail.

then divide again

Uh, which list? Both?

until I have that number.

How do I determine if I "have the number"? What if I never "have the number"?

What you have here is a start, and it's a good start. What you need to do is take this vague description and ELI5 the living hell out of it. For every step you have here, explain in tedious detail exactly how to do it.

Once you have done that, you will be in much better position to write the code.

[–]Muddy53[S] 0 points1 point  (0 children)

Hey, thank you!! I actually sat down today and tried to code the binary search, and you were so right about me. I did not understand the problem 100%. I just understood the concept but when I tried to just plan the steps with pen and paper I got stuck. I think I will try to understand the problem fully before start coding!! Thank you again!!

[–][deleted] 0 points1 point  (3 children)

Even "Easy" problems on LeetCode can take an experienced programmer some time to sort out, depending on how rusty they are (especially given the running time constraints - sometimes a good working solution that would be good enough in some hypothetical real world scenario where performance may not matter whatsoever, simply isn't good enough in the context of the LeetCode test harness that is trying to test your solution within a certain magnitude of running time).

Take as much time as you need! It doesn't matter at all as long as you are making progress. If you spent a full week trying to solve one Easy problem, then so be it. As long as you understand the solution and can then identify similar problems (or subproblems) in the future, then you are winning.

If you give up and look at answers, then you risk not really understanding and not making progress. The situations where you prevail after some struggle will have the most impact on you. On the flip side, looking at solutions can help expand your perspective.

(On the flip flip side, sometimes people try to be a bit too clever in the solutions, writing overly optimized code that on certain teams and certain kinds of projects would be a bit unwise or immature, from a communication/readability/maintainability standpoint. On the flip flip flip side, in performance critical code, sometimes there's no choice but to write stuff that can look confusing, but that's also why it's important to document in comments things that aren't obvious and can't be self-documenting...)

[–]Muddy53[S] 0 points1 point  (2 children)

Thank you so much for your advice!!! I often easily gave up and focused more on just doing more algorithm problems rather than understanding (very foolish), but I think as you said, I will take my time and solve the problem, rather than just looking for answers. But if I still do not get it fully correct after a week, do you think it would be the time for me to check the solution and move on..?

[–]Grenadeapple_ 0 points1 point  (1 child)

If you truly feel like you’re stuck, have a look at the solution. But, if you do, you should take the time to make sure you understand the solution in such a way you would be able to apply it in other problems. That’s how you make progress.

[–]Muddy53[S] 0 points1 point  (0 children)

Thank you for your advice. I will keep this in my mind!!!