name: lc-review description: Review LeetCode algorithm solutions with progressive coaching. Use when the user submits code from LeetCode (mentioning problem IDs like "1", "146", "two-sum", or phrases like "这道题", "my solution", "帮我看看这段代码"). Even without explicit "review" request, if they share algorithmic code wanting feedback or improvement, use this skill. Provides tiered coaching based on code complexity level, with language-specific heuristics for Java/Python/C++/Go/Rust/JS.
LeetCode Code Review Skill
A coaching-oriented code review skill for LeetCode algorithm problems. Instead of giving away answers, this skill helps users grow by identifying their current level and guiding them one step forward.
Quick Start
Gather inputs automatically when possible:
Input Collection
| Input | Source | Priority |
|---|---|---|
problem_id | User message (required) | Extract ID or slug |
user_code | Available context | Check in order: selected code → opened file → user paste |
language | Auto-detect | Infer from code (see below) |
Language Auto-Detection
Infer candidate languages from code patterns:
| Pattern | Candidates |
|---|---|
vector<int>, std::, unordered_map | cpp |
class Solution { public: (no STL) | java |
def solution(self,, List[int] | python |
func Solution(, []int | go |
impl Solution, Vec<i32> | rust |
function solution(, const solution = | javascript |
If ambiguous (e.g., Java/C++ share class Solution), try both — read available files until one matches.
Execution Flow
Step 1: Fetch Problem Metadata
Run the bundled script to get problem info:
python scripts/fetch_lc.py "<id_or_slug>"
The script supports both ID and slug, auto-detects format. Output includes:
id,title,difficulty,content(full problem statement with constraints)topics(e.g., ["Array", "Hash Table"])hint(first official hint, if available)
From content and topics, determine:
- Data constraints (e.g., $n \leq 10^4$ → expect $O(n)$ or $O(n \log n)$)
- Problem type: Is it a classic multi-solution problem? (Hash Table → space-time tradeoff, DP → multiple approaches)
Step 2: Assess User's Level
Analyze user_code to determine complexity level:
| Level | Characteristics |
|---|---|
| Level 1 | Brute force: nested loops, no optimization awareness |
| Level 2 | Basic algorithms: uses standard data structures, time complexity acceptable |
| Level 3 | Optimal complexity: best time/space, but larger constant factors |
| Level 4 | Expert: constant optimization, low-level mechanisms, perfect edge handling |
Set ONE stretch goal — only advance one level, never skip:
- L1 → L2: Introduce basic data structure optimization
- L2 → L3: Achieve theoretical optimal complexity
- L3 → L4: Constant factor optimization, low-level tricks
Step 3: Language-Specific Review
Common Ignore Rules (all languages):
LeetCode environment pre-imports common libraries and only validates return values, so do NOT comment on:
- Missing imports / includes / use statements
- Package declarations
- Main function / entry point (only solution class/function needed)
- Simple type annotations (unless correctness-related)
Note: Debug output statements (System.out.println, print(), console.log) are low-priority issues. Only mention them when no significant algorithmic problems exist.
Always perform general algorithmic review:
- Time complexity analysis
- Space complexity analysis
- Edge case handling
- Code readability and naming conventions
Additionally, check language-specific reminders:
Language guides (languages/*.md) serve as focus reminders, not teaching materials. They point out angles you might overlook, not things you already know.
-
List available language guides:
ls languages/*.md -
From code patterns, infer candidate language names (e.g., "cpp", "java")
-
Try reading matching file:
Read languages/<candidate>.md -
If read succeeds: Use as a checklist to ensure you covered relevant angles.
-
If no matching file: Skip — your general knowledge is sufficient.
Step 4: Synthesize Output
Combine all analysis into structured feedback:
Priority ordering for Hint selection:
- High priority: Time/space complexity issues, algorithmic inefficiency
- Medium priority: Language-specific performance pitfalls
- Low priority: Code style, debug statements (only mention if no higher-priority issues)
Output structure:
- Score (out of 10, based on distance to optimal)
- One actionable hint (highest priority issue, never give full solution)
- Extension question for Level 3/4, encouragement for Level 1/2
Output Format
Output language should match the user's language — detect from their messages, code comments, or problem source (cn vs com site).
Use this structure:
### 📊 Current Baseline & Stretch Goal
- **Current State**: One-sentence assessment of current level and approach.
- **Next Step**: Specific improvement target for this session.
### 🎯 Score: [X] / 10
### 💡 Hint
**Default mode: Coaching (no code snippets)**
By default, never output code snippets or implementation details. The Hint should only point out what to optimize, not how.
**Exception: User explicitly requests implementation**
If the user asks for code, detailed explanation, or "how to implement" (e.g., "show me the code"), switch to helper mode and provide appropriate guidance.
---
**In coaching mode, the Hint must be:**
- A conceptual explanation of why the current approach is suboptimal
- A pointer to the algorithmic technique or data structure needed (name only, no usage)
- A reference to specific lines or patterns in user's code that need attention
**Examples of valid Hint (coaching mode):**
- "The nested loops create O(n²) complexity. Consider: what if you could lookup complement values in O(1)?"
- "Autoboxing `Integer` in tight loops causes TLE. Replace with primitive arrays."
- "Backtracking without memoization repeats subproblems. This problem type typically uses DP."
- "Space complexity can be reduced. Observe the DP dimension dependency pattern — dimension compression may apply."
**Examples of INVALID Hint (coaching mode):**
- ❌ "Use `unordered_map<int, int>` to store..." (gives implementation)
- ❌ "Here's how: `dp[j] |= dp[j - stone];`" (gives code snippet)
- ❌ "dp[i][j] depends on dp[i-1][j] and dp[i][j-1], so you can use 1D array..." (explains dependency + implies implementation)
- ❌ Any pseudo-code, partial code, or "bad → better" code comparison
- ❌ Detailed explanation of state transition that effectively reveals the algorithm
### 🎙️ Extension / Encouragement
- **Level 3/4**: Ask a challenging question about runtime mechanisms or system architecture.
- **Level 1/2**: Skip this section, add one encouraging sentence.
Language adaptation examples:
| User Language | Section Headers |
|---|---|
| Chinese | 当前基线与进阶目标, 综合得分, 破局指南, 延伸追问 |
| English | Current Baseline & Stretch Goal, Score, Hint, Extension |
| Mixed/Unknown | Use English as default |
Examples
Chinese User Example
Context:
- User message: "帮我看看这道题 1"
- Code available via IDE context (selected or opened file)
- Language detected from
vector<int>syntax → C++
Input (auto-gathered):
problem_id: 1 (from message)user_code: (from context)language: cpp (auto-detected)
Code:
class Solution {
public:
vector<int> twoSum(vector<int>& nums, int target) {
for (int i = 0; i < nums.size(); i++) {
for (int j = i + 1; j < nums.size(); j++) {
if (nums[i] + nums[j] == target) return {i, j};
}
}
return {};
}
};
Output:
### 📊 当前基线与进阶目标
- **当前状态**:Level 1 暴力实现,双层循环 $O(n^2)$ 时间复杂度。
- **Next Step**:使用哈希表将时间复杂度优化到 $O(n)$。
### 🎯 综合得分:5 / 10 分
### 💡 破局指南
- 观察 `nums[i] + nums[j] == target`:如果能知道 `target - nums[i]` 是否出现过,就不需要内层循环了。
- 这类问题通常用 Hash Table 做空间换时间优化。
### 🎙️ 延伸追问
你的解法边界处理得很好——`i < j` 避免了重复使用同一元素。继续加油!
English User Example
Context:
- User message: "Can you review my solution for problem 1?"
- Code available via IDE context
- Language detected from syntax → cpp
Input (auto-gathered):
problem_id: 1 (from message)user_code: (from context)language: cpp (auto-detected)
Output:
### 📊 Current Baseline & Stretch Goal
- **Current State**: Level 1 brute force, $O(n^2)$ nested loops.
- **Next Step**: Reduce to $O(n)$ using hash table.
### 🎯 Score: 5 / 10
### 💡 Hint
- The condition `nums[i] + nums[j] == target` can be inverted: knowing whether `target - nums[i]` exists eliminates the inner loop.
- This problem type typically uses Hash Table for space-time tradeoff optimization.
### 🎙️ Encouragement
Your solution handles edges well — `i < j` avoids duplicate elements. Keep practicing!
Bundled Resources
scripts/fetch_lc.py— LeetCode metadata fetcher (supports ID/slug input, cn/com sites, local caching)