Coach me through this LeetCode-style programming problem without skipping the reasoning. Problem statement: [PROBLEM STATEMENT] Language and version: [LANGUAGE] My current attempt or idea: [CURRENT ATTEMPT] What I understand and where I am stuck: [STUCK POINT] Preferred help level: [HELP LEVEL] If the problem statement lacks constraints, examples, or the required function signature, ask up to 3 clarifying questions before solving. Do not assume hidden constraints or change the input/output contract.
First, restate the problem in one sentence and identify the input size, mutation rules, and important constraints from the statement. Then respond according to my help level: for "hint," give only the next useful observation and one question for me to answer; for "guided," reveal the approach in checkpoints; for "full," provide the complete solution after the reasoning.
For a full answer, include:
1. The algorithmic pattern and why it fits this problem rather than a similar-looking alternative.
2. A step-by-step derivation from brute force to the chosen approach.
3. A concise correctness argument covering the invariant or case split.
4. Complete compilable [LANGUAGE] code in the required LeetCode class/function format.
5. Time and space complexity, including any recursion-stack cost.
6. A dry run on one supplied example and a table of edge cases: empty or smallest input if valid, duplicates, negatives, boundaries, and overflow or recursion depth where relevant.
Before answering, verify that every loop pointer, index, and base case is valid; that complexity matches the code; and that the solution does not rely on an unsupported library, input format, or invented constraint. If my attempt is close, explain the smallest correction before showing a replacement.Fill in
| Placeholder | What to enter | Example |
|---|---|---|
| [PROBLEM STATEMENT] | Paste the complete problem, including examples, constraints, and required method signature. | Given an array nums and integer k, return the maximum length of a subarray that sums to k. nums may contain negative integers. Return 0 if none exists. |
| [LANGUAGE] | Name the programming language you want the solution in. | Python 3 |
| [CURRENT ATTEMPT] | Paste your code or describe the approach you have tried. | I tried a sliding window but it fails on [1, -1, 5, -2, 3] with k = 3. |
| [STUCK POINT] | State the exact step you cannot solve or do not understand. | I do not see how to handle negative numbers while keeping the result O(n). |
| [HELP LEVEL] | Enter hint, guided, or full to control how much of the solution is revealed. | guided |
How to use
- Paste the full statement and constraints, not a title or screenshot transcription alone.
- Choose hint when practicing under interview conditions and move to guided only after attempting the question.
- Compare the dry run with your own trace, especially pointer movement or hash-map updates.
- Follow up with: "Give me a new test case that breaks my original approach, but do not reveal the answer until I trace it."
Variations
Hint-only coach
Use this when you want to preserve the struggle and avoid seeing a solution too early.
Act as a hint-only algorithms coach for this problem: [PROBLEM]. My language: [LANGUAGE] My attempted approach: [ATTEMPT] Give one hint at a time, no code and no named final algorithm unless I ask. Each hint should point to a property, invariant, or counterexample that advances my attempt. After each hint, ask me one question to answer before continuing. If I make a mistake, explain why using a minimal counterexample rather than solving it for me. Ask up to 3 clarifying questions only if the statement, constraints, or attempt is incomplete.
Complexity review
Use this after coding a solution and you want to verify its complexity claim.
Review the correctness and complexity of my LeetCode solution. Problem and constraints: [PROBLEM] Code: [CODE] My claimed complexity: [CLAIM] Trace the code on one normal case and one adversarial boundary case. Then report: correctness verdict, any counterexample, actual time complexity, actual auxiliary space including call stack, and minimal changes needed. Check nested loops that do not always run fully, amortized operations, hash-table assumptions, sorting cost, recursion depth, integer overflow, and mutation of inputs. Do not rewrite the solution unless there is a defect. Ask up to 3 questions only if the problem contract is missing.
Interview explanation
Use this after solving a problem and want to practice explaining it aloud.
Turn my solution into a concise technical interview explanation. Problem: [PROBLEM] Solution code or outline: [SOLUTION] Audience level: [INTERVIEW LEVEL] Write a 2-minute spoken answer covering the brute-force baseline, key insight, algorithm, correctness intuition, complexity, and one edge case. Then give three likely interviewer follow-up questions with strong, factual answers. Keep claims consistent with the supplied solution and do not imply a proof or optimization that the code lacks. Ask up to 3 clarifying questions only if the input constraints or solution are absent.
Tips
- Constraints determine the pattern: a sorted array changes two-pointer options, while negative values usually invalidate a sum-based sliding window.
- For hash-map prefix solutions, write down exactly what the map stores and whether you preserve the first or latest index; that choice often decides correctness.
- A complexity claim needs to include sorting, copying, and recursion stack, not only the visible loop count.
- Use counterexamples designed around duplicates, one-element inputs, and boundary values before accepting an answer.
FAQ
Will this prompt help me learn instead of just giving answers?
Yes. Set the help level to hint or guided and require the model to wait for your answer between hints.
Can AI verify a LeetCode solution?
It can reason through supplied code and cases, but you should still run it in the target judge because language and hidden constraints matter.
Why include the full problem statement?
Details such as negative inputs, mutation rules, and size limits can completely change the valid approach.