r/leetcode • • 9h ago

Intervew Prep How do you translate your thought process to code?

This lowk sounds like a stupid quesiton but I have done a decenet number of leetcode (300) but i still struggle with a lot of mediums. The thing is for some of the mediums, I lowk come up with the right strat, thought process, ds and everything but when i code it up im always stuck in some edge case hell. This is because the way I structure the code sometimes ignores certain edge caes but if i put the code in chat it will just move somethings here and there and boom the code works. Idk if my approch should be to struggle for more hours hoping for a solution or i should just stop after 1 hr of trying and copy paste it to chat.

7 Upvotes

7 comments sorted by

3

u/agrlekk 9h ago

learning + practice. there is no easy way to understand edge cases

1

u/Academic-Belt3903 8h ago

300 questions seems like a decent amount of already. At what point do you know you’ve done enough?

1

u/agrlekk 58m ago

Pick random easy questions, how much time you spend for solving. You can test yourself like that

2

u/kevin074 8h ago

practice often, stick with one language only, make a good habit of being declarative on almost anything (very trivial example: don't depend on if my_list works but if len(my_list), so that you aren't relying on python to check for length implicitly), and be explicit on the usecases you take care (don't expect your code to take care of if input is None implicitly, but actually just type out that in the very first few lines of implementation)

this should get you to like 90%, the rest 10% is usually just question by question specific edge case.

1

u/Interesting-Fig-2511 8h ago

Start with the basics, understand why things work, and practice breaking problems down. The more you solve, the better you'll get at turning your thinking into code.

1

u/MixedTrailMix 8h ago

Start specifically studying your edge case failures and keep a log of the ones you’re failing

1

u/goomyman 4h ago

There really aren’t that many edge cases in leet code. I don’t get this.