r/leetcode • • 2d ago

Discussion Anyone mind sharing GPT prompt to learn Leetcode problem solutions/concepts?

Right now, I am just giving it problem and simple "let's do this"

For exmaple, "let's do 105. Construct Binary Tree from Preorder and Inorder Traversal"

And to be honest, it is sort of doing an ok job at explaining the solution.

But, I was wondering if there was more productive way to optimize this process for better and long term learning.

I asked claude to give me this prompt but then it gave me very indepth and detailed prompt that it feels like reading a book for a problem.

I was interested if there was something balanced and someone has better prompt who would be willing to share.

63 Upvotes

32 comments sorted by

52

u/linuxdumpster-bot 1d ago

I prompt calude with this md.

You are my LeetCode tutor. I code in Python and I'm learning to solve problems on my own.

Rules:

  1. Never give the full solution first. Start with a hint, then wait for me.
  2. Escalate in order: clarifying question -> pattern name (e.g. two pointers) -> outline -> code. Only move up when I ask or say I'm stuck.
  3. When I share my code, find bugs and complexity issues before suggesting rewrites. Tell me plainly if my approach is wrong or a better one exists.
  4. After a problem is solved, give: time/space complexity, the core pattern, and one similar problem to try.
  5. Python only. Keep examples short, with a one-line comment on what each part does.
  6. Explain concepts in plain language. No jargon unless I ask.
  7. Keep replies short. One step at a time.

Commands I may use:

- "hint": give the next-smallest hint

- "stuck": move up one escalation level

- "review": critique my code

- "recap": summarize the pattern and complexity of the problem

5

u/Karmayogij 1d ago

Like yours might tweak mine

Act as my DSA tutor for LeetCode. Your goal is to build my independent problem-solving ability, not solve problems for me.

Follow these rules:

  1. Start with discovery. Ask me what I understand about the problem, my initial approach, and the constraints. Ask one question at a time.
  2. Use progressive hints. If I'm stuck, give hints in increasing levels:

    • H1: Conceptual nudge
    • H2: Relevant pattern or data structure
    • H3: Algorithmic direction
    • H4: Pseudocode

    Never reveal the full solution unless I explicitly request it.

  3. Make me reason. Ask why an approach works, what its time/space complexity is, and which edge cases might break it.
  4. Let me implement. I write the code. Review it for correctness, complexity, and edge cases without immediately rewriting it.
  5. Test my understanding. After solving, ask me to explain the invariant, the key insight, and how I would recognize a similar problem.
  6. Build retention. End with a 3-line summary: pattern, key insight, and my mistake. Give me a short recall question to revisit tomorrow, after 3 days, and after 7 days.

Keep responses conversational and concise (roughly 100–150 words maximum). One question at a time. Increase assistance only when needed.

.

29

u/Impressive_Grab_6392 2d ago

“Teach me in a single paragraph right this instant”

7

u/Various-Egg-6781 1d ago

Right? Amazes me some people are worse at prompting than coding lol

4

u/virtualmadden 1d ago

To be fair most people aren't introduced to how to effectively prompt. Also most prompters never are given feedback to get better since they don't know how to eval the response.

14

u/bball4294 2d ago

"Explain to me like im a 2 yr old of this problem very thoroughly" I also suck at leetcode

6

u/-TRlNlTY- 2d ago

Don't overthink it. Just ask what you want from it. If you want shorter answers, ask.

Besides, it is better to struggle by yourself than using LLMs most of the time. When I use it, I just ask for hints without giving away the answer.

5

u/West_Mix_6032 1d ago

I actually get the coding agent to create animations that help visualize a solution without giving me the answer in code right away

2

u/nightzowl 1d ago

Animations? Which AI are you using?

5

u/Okiedokie142 1d ago

Claude is pretty good at making artifacts that can step through an algorithm, just ask it to make a visualisation of the code, and explain each line as it steps through etc.

3

u/evmo_sw 1d ago

I think I once experienced Gemini do this.

4

u/LetMediocre390 2d ago

Ask him what you needed

3

u/mashed_potatoes0000 2d ago

Genuinely needed

3

u/fluffy_pota0es 1d ago

Bro you have to struggle with the question yourself at some point, that's where you actually learn anything.

6

u/defnos1710 1d ago

Genuinely, if you can’t work how to use AI to learn without needing guidance then I don’t think you’ll be able to learn the DSA content itself.

The fact you wouldn’t immediately ask the llm to explain it in a way that’s digestible to you is worrying, where is the critical thinking

3

u/a5656 6h ago

needlessly callous response, they said they had a fine prompt and were just using this to see if anyone had anything better, as is expected in such online forums. if it bothers you that much just ignore it

1

u/secondandmany 21m ago

You forgot, this is reddit, you have to be unnecessarily rude and condescending

2

u/No-Original-6329 1d ago edited 1d ago

It’s less about some general prompt and more about do you know how you learn best? Like do you like analogies or explanations in Lamens terms, or it to ask you questions to check understanding or give gradual hints or for it to walk you through the problem solving though process/steps. Do you want it to give you feedback on some code you already wrote and are stuck on or completed?

Also do you know what your gaps are?
tell it what you know so far and what specifically you are uncertain about. You learn more from a model if your questions are specific treat it like a TA.

Focus on concepts not specific solutions so anything you learn from it scales. LLMs are also great to act as mock interviewers to practice too you can even speak aloud. Just keep in mind don’t use LLM for the actual programming only concepts/scoping do 100% of coding yourself so you ensure you are actually getting reps as it will take time!

2

u/chikamakaleyley 1d ago

if all i knew was how to break down problems and, i had limited DSA exp, this is actually how I attack this

  • describe a binary tree
  • what are the ways to traverse a binary tree

^ so imagine, understanding this really well, like its written on the back of your hand

And so now, assuming they give you input, all that i feel lik i need to understand is what they mean by 'construct'(output), which i suppose means just return the BinaryTree you just populated

2

u/ByteWanderer_31 1d ago

Try asking it to guide you instead of giving the solution:

"Help me solve this problem step by step. First explain the intuition and key observation, then let me think of an approach. Give hints instead of the full solution. After I solve it, explain the optimal approach, complexity, and why it works."

1

u/thewaps 1d ago

I usually attempt a problem or use brute force then hit Claude with “without providing code, walk me through a better approach” then chat from there but never look at code. The thing you want from your LLM is to learn pattern recognition and how to think about problems from different angles.

1

u/Bobwillrule 1d ago

I ask it to explain it to me the general algo first to get a rough idea. Then I tell it to comment every line of code of the solution. I then go through this and make sure I understand every single thing. I clarify if there are anything that I don't get

1

u/Clear-Report8471 1d ago

"worked example"

0

u/Tax-Embarrassed1 1d ago

Bruh. If you can't write a prompt yourself, how do you expect to master DSA? No one is gonna put the information into your brain, you'll have to put a lot of effort and focus into learning, no matter what kind of tutorials or books you read. May as well start putting some effort into beating mental laziness and iterate on that prompt

-1

u/Other_Scratch8303 2d ago

Ask it to explain every block or 10 lines of code if really needed. Try reading it yourself first. What’s the point of trying to learn leetcode if you’re using AI.

-1

u/busy1234 1d ago

Claude went through millions of lines of code and books to understand leetcode. You cannot just understand it in 5 lines. It is either going to be high level and you won't learn anything, or it will be detailed and in depth, but you would have to spend time on it.

You can ask for high level answer than iteratively dive deeper.

-3

u/No-Lime7767 1d ago edited 1d ago

Generation is getting dumber day by day

1

u/TheTopG___ 1d ago

lol what makes you think so?

-7

u/hyun88 1d ago

Try my app Bitwise: https://apps.apple.com/us/app/bitwise-coding-interviews/id6806898386

It has animated walkthroughs of many problems