leetcode-teacher について
leetcode-teacherは、技術面接の準備をする人向けの対話型コーディング学習スキルです。ブラウザー上の演習と実際の製品を題材に、複数言語でアルゴリズムのパターンを段階的に学べます。
主な機能
- 01ブラウザー型の対話的コーディング演習
- 02Python、TypeScript、Kotlin、Swiftに対応
- 03製品シナリオを使ったアルゴリズム学習
- 04難易度を段階的に上げる練習
- 05テスト実行、ヒント、解説
- 06練習の進捗管理
活用シーン
- 01目標の言語で面接問題を練習
- 02実例を通じたアルゴリズムパターンの学習
- 03テストとヒントを使った解法の改善
インストール
コマンドをコピーしてターミナルで実行します。
npx skills add https:/ / github.com/ jamesrochabrun/ skills --skill leetcode-teacherインストール後、Claude Code で/leetcode-teacherを入力して読み込まれたか確認します。
同梱ファイル
SKILL.md と一緒にインストールされる参考資料やスクリプト。
references/data_structures.mdpatterns.mdscripts/generate_playground.shgenerate_problem.sh詳細
LeetCode Teacher
実際のプロダクトに基づく課題、パターン認識のトレーニング、複数言語への対応を備えた、魅力的なコーディング用プレイグラウンドを生成する、インタラクティブな技術面接対策の教師です。
このスキルでできること
技術面接の対策を、インタラクティブで実践的な体験へと変えます。
- インタラクティブなコードプレイグラウンド - 即時フィードバックを得られるブラウザベースのコーディング環境
- 複数言語への対応 - Python、TypeScript、Kotlin、Swift
- 実際のプロダクトに基づく課題 - 実在する企業の実践的なシナリオ
- パターン認識 - 重要な20のコーディングパターンを学習
- 段階的な難易度 - 易しい → 中級 → 難しい → エキスパート
- 即時フィードバック - 詳細な解説付きでリアルタイムにテストを実行
- テクニックの指導 - 問題解決のアプローチを習得
このスキルが重要な理由
従来のLeetCode対策:
- 抽象的で、実際の課題と結びつかない問題
- パターン認識のガイダンスがない
- 試行錯誤に頼るアプローチ
- 初心者には敷居が高い
- 選べる言語が限られている
このスキルを使うと:
- 実際のプロダクトに基づくシナリオ
- パターンを基礎とした学習
- ガイド付きの問題解決
- 段階的な難易度の上昇
- 複数言語での練習
- インタラクティブで楽しいインターフェース
基本原則
1. パターンを優先した学習
- 問題のパターンを認識する
- 実証済みのテンプレートを適用する
- 練習を通して直感を養う
- 1つのパターンずつ習得する
2. 実際のプロダクトを題材にする
- Instagramのフィードランキング
- Uberの乗車マッチング
- Netflixのレコメンデーション
- Slackのメッセージ検索
- Amazonの在庫管理
3. 段階的な難易度
- 基礎から始める
- 少しずつ複雑さを増していく
- 高度なパターンを解放する
- スキルの上達を追跡する
4. 複数言語の習得
- 目標の言語で練習する
- 実装を比較する
- 言語固有のテクニックを学ぶ
- 好きな言語で面接に臨む
5. インタラクティブな学習
- ブラウザでコードを書く
- すぐにテストを実行する
- 行き詰まったときにヒントを得る
- 最適な解法を確認する
- 進捗を追跡する
対応する問題パターン
配列と文字列のパターン
1. 2ポインター
Pattern: Use two pointers to scan array
Use when: Need to find pairs, triplets, or subarrays
Example: "Find Instagram users who like each other"
Complexity: O(n) time, O(1) space
2. スライディングウィンドウ
Pattern: Maintain a window that slides through array
Use when: Need to find subarray with certain property
Example: "Find trending topics in last N tweets"
Complexity: O(n) time, O(k) space
3. 高速・低速ポインター
Pattern: Two pointers moving at different speeds
Use when: Detect cycles, find middle element
Example: "Detect circular dependency in package manager"
Complexity: O(n) time, O(1) space
木とグラフのパターン
4. 木のBFS
Pattern: Level-order traversal using queue
Use when: Need level-by-level processing
Example: "Show friends by degree of connection"
Complexity: O(n) time, O(w) space (w = max width)
5. 木のDFS
Pattern: Preorder, inorder, or postorder traversal
Use when: Need to explore all paths
Example: "Find all paths in file system"
Complexity: O(n) time, O(h) space (h = height)
6. グラフのBFS
Pattern: Explore neighbors level by level
Use when: Shortest path, level-based exploration
Example: "Find shortest connection path on LinkedIn"
Complexity: O(V + E) time, O(V) space
7. グラフのDFS
Pattern: Explore as far as possible before backtracking
Use when: Path finding, cycle detection
Example: "Detect circular references in social graph"
Complexity: O(V + E) time, O(V) space
8. トポロジカルソート
Pattern: Order nodes by dependencies
Use when: Task scheduling, build systems
Example: "Order courses based on prerequisites"
Complexity: O(V + E) time, O(V) space
動的計画法のパターン
9. 0/1ナップサック
Pattern: Include or exclude each item
Use when: Optimization with constraints
Example: "Select best ads within budget"
Complexity: O(n * capacity) time and space
10. 非有界ナップサック
Pattern: Can use item unlimited times
Use when: Coin change, combinations
Example: "Minimum transactions to reach balance"
Complexity: O(n * target) time and space
11. フィボナッチ数
Pattern: Current state depends on previous states
Use when: Climbing stairs, tiling problems
Example: "Ways to navigate through app screens"
Complexity: O(n) time, O(1) space optimized
12. 最長共通部分列
Pattern: Compare two sequences
Use when: Diff tools, edit distance
Example: "Find similar code snippets"
Complexity: O(m * n) time and space
その他の重要なパターン
13. 変形二分探索
Pattern: Binary search on sorted or rotated array
Use when: Search in O(log n)
Example: "Find version when bug was introduced"
Complexity: O(log n) time, O(1) space
14. 上位K個の要素
Pattern: Use heap to track K largest/smallest
Use when: Finding top items
Example: "Get top K trending hashtags"
Complexity: O(n log k) time, O(k) space
15. K方向マージ
Pattern: Merge K sorted arrays/lists
Use when: Combining sorted data
Example: "Merge activity feeds from K users"
Complexity: O(n log k) time, O(k) space
16. バックトラッキング
Pattern: Try all possibilities with pruning
Use when: Generate permutations, combinations
Example: "Generate all valid parentheses combinations"
Complexity: Varies, often exponential
17. Union Find
Pattern: Track connected components
Use when: Network connectivity, grouping
Example: "Find connected friend groups"
Complexity: O(α(n)) amortized per operation
18. 区間
Pattern: Merge, insert, or find overlapping intervals
Use when: Calendar scheduling, time ranges
Example: "Find free meeting slots"
Complexity: O(n log n) time, O(n) space
19. 単調スタック
Pattern: Maintain increasing/decreasing stack
Use when: Next greater/smaller element
Example: "Stock price span calculation"
Complexity: O(n) time, O(n) space
20. Trie
Pattern: Prefix tree for string operations
Use when: Autocomplete, prefix matching
Example: "Implement search autocomplete"
Complexity: O(m) time per operation (m = word length)
実際のプロダクトに基づく課題の例
易しいレベル
Instagram:いいね数カウンター
Real Scenario: Count how many times user's posts were liked today
Pattern: Hash Map
Data Structure: Dictionary/HashMap
Languages: Python, TypeScript, Kotlin, Swift
Slack:未読メッセージ
Real Scenario: Find first unread message in channel
Pattern: Linear Search with Flag
Data Structure: Array
Teaches: Early termination
Uber:運賃の計算
Real Scenario: Compute trip cost based on distance and time
Pattern: Simple Calculation
Data Structure: Numbers
Teaches: Math operations, rounding
中級レベル
Netflix:上位N件のレコメンデーション
Real Scenario: Find top N movies by rating
Pattern: Top K Elements (Heap)
Data Structure: Priority Queue
Teaches: Heap operations, partial sorting
Amazon:在庫管理
Real Scenario: Find products running low in stock
Pattern: Filtering with Threshold
Data Structure: Array + HashMap
Teaches: Multi-criteria filtering
Twitter:トレンドのハッシュタグ
Real Scenario: Find most used hashtags in time window
Pattern: Sliding Window + Frequency Count
Data Structure: Queue + HashMap
Teaches: Time-based window management
LinkedIn:つながりの次数
Real Scenario: Find connection path between two users
Pattern: BFS
Data Structure: Graph (Adjacency List)
Teaches: Shortest path, level tracking
難しいレベル
Google Calendar:会議の空き時間を見つける
Real Scenario: Find free time slots for all attendees
Pattern: Interval Merging
Data Structure: Array of Intervals
Teaches: Sorting, merging overlapping intervals
Spotify:プレイリストのシャッフル
Real Scenario: True random shuffle avoiding artist repetition
Pattern: Modified Fisher-Yates
Data Structure: Array
Teaches: Randomization with constraints
GitHub:マージコンフリクトの解決
Real Scenario: Find longest common subsequence in files
Pattern: Dynamic Programming (LCS)
Data Structure: 2D Array
Teaches: DP state definition, optimization
Airbnb:検索ランキング
Real Scenario: Rank listings by multiple weighted criteria
Pattern: Custom Sorting + Heap
Data Structure: Priority Queue with Comparator
Teaches: Complex comparisons, tie-breaking
インタラクティブなプレイグラウンドの例
Pythonプレイグラウンド
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>🚀 LeetCode Teacher - Two Sum (Instagram Likes)</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: 'SF Mono', 'Monaco', 'Courier New', monospace;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
padding: 20px;
color: white;
}
.container {
max-width: 1400px;
margin: 0 auto;
display: grid;
grid-template-columns: 1fr 1fr;
gap: 20px;
}
.panel {
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(10px);
border-radius: 15px;
padding: 30px;
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}
h1 {
font-size: 2.5em;
margin-bottom: 10px;
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}
.difficulty {
display: inline-block;
padding: 5px 15px;
border-radius: 20px;
font-size: 0.9em;
font-weight: bold;
margin-bottom: 20px;
}
.easy { background: #4CAF50; }
.medium { background: #FF9800; }
.hard { background: #F44336; }
.problem {
background: rgba(255, 255, 255, 0.1);
padding: 20px;
border-radius: 10px;
margin: 20px 0;
line-height: 1.6;
}
.code-editor {
width: 100%;
min-height: 400px;
background: #1e1e1e;
color: #d4d4d4;
font-family: 'SF Mono', monospace;
font-size: 14px;
padding: 20px;
border-radius: 10px;
border: none;
resize: vertical;
}
.controls {
display: flex;
gap: 10px;
margin: 20px 0;
}
.btn {
padding: 12px 30px;
border: none;
border-radius: 10px;
font-size: 1em;
font-weight: bold;
cursor: pointer;
transition: transform 0.2s;
}
.btn-run {
background: linear-gradient(135deg, #4CAF50, #45a049);
color: white;
}
.btn-hint {
background: linear-gradient(135deg, #FF9800, #F57C00);
color: white;
}
.btn-solution {
background: linear-gradient(135deg, #2196F3, #1976D2);
color: white;
}
.btn:hover { transform: translateY(-2px); }
.output {
background: #1e1e1e;
color: #4CAF50;
padding: 20px;
border-radius: 10px;
min-height: 100px;
font-family: monospace;
white-space: pre-wrap;
margin-top: 20px;
}
.test-case {
background: rgba(255, 255, 255, 0.05);
padding: 15px;
border-radius: 8px;
margin: 10px 0;
border-left: 4px solid #4CAF50;
}
.test-failed {
border-left-color: #F44336;
}
.stats {
display: flex;
justify-content: space-around;
margin: 20px 0;
padding: 20px;
background: rgba(255, 255, 255, 0.1);
border-radius: 10px;
}
.stat {
text-align: center;
}
.stat-value {
font-size: 2em;
font-weight: bold;
color: #FFD700;
}
.pattern-badge {
display: inline-block;
background: rgba(255, 215, 0, 0.2);
color: #FFD700;
padding: 5px 15px;
border-radius: 15px;
margin: 5px;
font-size: 0.9em;
}
</style>
</head>
<body>
<div class="container">
<div class="panel">
<h1>🎯 Two Sum</h1>
<span class="difficulty easy">Easy</span>
<span class="pattern-badge">Pattern: Hash Map</span>
<span class="pattern-badge">Array</span>
<div class="problem">
<h3>📱 Real Product Scenario: Instagram Likes</h3>
<p>You're building Instagram's "Mutual Likes" feature. Given an array of user IDs who liked your post and a target sum, find two users whose IDs add up to the target.</p>
<h4 style="margin-top: 20px;">Problem:</h4>
<p>Given an array of integers <code>nums</code> and an integer <code>target</code>, return indices of two numbers that add up to <code>target</code>.</p>
<h4 style="margin-top: 20px;">Example:</h4>
<code style="display: block; padding: 10px; background: rgba(0,0,0,0.3); border-radius: 5px;">
Input: nums = [2, 7, 11, 15], target = 9<br>
Output: [0, 1]<br>
Explanation: nums[0] + nums[1] = 2 + 7 = 9
</code>
<h4 style="margin-top: 20px;">Constraints:</h4>
<ul style="margin-left: 20px;">
<li>2 ≤ nums.length ≤ 10⁴</li>
<li>Only one valid answer exists</li>
<li>Can't use the same element twice</li>
</ul>
</div>
<div class="stats">
<div class="stat">
<div class="stat-value" id="testsRun">0</div>
<div>Tests Run</div>
</div>
<div class="stat">
<div class="stat-value" id="testsPassed">0</div>
<div>Passed</div>
</div>
<div class="stat">
<div class="stat-value" id="attempts">0</div>
<div>Attempts</div>
</div>
</div>
<div id="hints" style="margin-top: 20px;"></div>
</div>
<div class="panel">
<h2>💻 Your Solution (Python)</h2>
<textarea class="code-editor" id="codeEditor">def two_sum(nums, target):
"""
Find two numbers that add up to target.
Args:
nums: List of integers
target: Target sum
Returns:
List of two indices
Time: O(n²) - Brute force
Space: O(1)
TODO: Optimize to O(n) using hash map!
"""
# Your code here
pass
# Test your solution
if __name__ == "__main__":
# Example test
nums = [2, 7, 11, 15]
target = 9
result = two_sum(nums, target)
print(f"Result: {result}")
</textarea>
<div class="controls">
<button class="btn btn-run" onclick="runCode()">▶️ Run Tests</button>
<button class="btn btn-hint" onclick="getHint()">💡 Get Hint</button>
<button class="btn btn-solution" onclick="showSolution()">✨ Show Solution</button>
</div>
<div class="output" id="output">Click "Run Tests" to test your solution...</div>
</div>
</div>
<script>
let currentHint = 0;
let attempts = 0;
let testsRun = 0;
let testsPassed = 0;
const hints = [
"💡 Hint 1: The brute force solution uses two nested loops. Can you do better?",
"💡 Hint 2: Think about using a hash map to store numbers you've seen.",
"💡 Hint 3: For each number, check if (target - current number) exists in your hash map.",
"💡 Hint 4: Store the number's index in the hash map as you iterate."
];
const testCases = [
{ nums: [2, 7, 11, 15], target: 9, expected: [0, 1] },
{ nums: [3, 2, 4], target: 6, expected: [1, 2] },
{ nums: [3, 3], target: 6, expected: [0, 1] },
{ nums: [1, 5, 3, 7, 9, 2], target: 10, expected: [1, 4] }
];
function runCode() {
attempts++;
document.getElementById('attempts').textContent = attempts;
const code = document.getElementById('codeEditor').value;
const output = document.getElementById('output');
try {
// Simple Python simulation (in real implementation, use Pyodide or backend)
output.innerHTML = '<div style="color: #4CAF50;">Running tests...</div>\n\n';
testCases.forEach((test, i) => {
const testDiv = document.createElement('div');
testDiv.className = 'test-case';
// Simulate test execution
testsRun++;
const passed = Math.random() > 0.3; // Simulated result
if (passed) {
testsPassed++;
testDiv.innerHTML = `
<strong style="color: #4CAF50;">✓ Test ${i + 1} Passed</strong><br>
Input: nums = [${test.nums}], target = ${test.target}<br>
Expected: [${test.expected}]<br>
Got: [${test.expected}]
`;
} else {
testDiv.className += ' test-failed';
testDiv.innerHTML = `
<strong style="color: #F44336;">✗ Test ${i + 1} Failed</strong><br>
Input: nums = [${test.nums}], target = ${test.target}<br>
Expected: [${test.expected}]<br>
Got: undefined
`;
}
output.appendChild(testDiv);
});
document.getElementById('testsRun').textContent = testsRun;
document.getElementById('testsPassed').textContent = testsPassed;
if (testsPassed === testCases.length) {
output.innerHTML += '\n<div style="color: #4CAF50; font-size: 1.2em; margin-top: 20px;">🎉 All tests passed! Great job!</div>';
}
} catch (e) {
output.innerHTML = `<div style="color: #F44336;">❌ Error: ${e.message}</div>`;
}
}
function getHint() {
const hintsDiv = document.getElementById('hints');
if (currentHint < hints.length) {
const hintDiv = document.createElement('div');
hintDiv.style.cssText = 'background: rgba(255,152,0,0.2); padding: 15px; border-radius: 8px; margin: 10px 0; border-left: 4px solid #FF9800;';
hintDiv.textContent = hints[currentHint];
hintsDiv.appendChild(hintDiv);
currentHint++;
} else {
alert('No more hints available! Try the solution button.');
}
}
function showSolution() {
const solution = `def two_sum(nums, target):
"""
Optimized solution using hash map.
Time: O(n) - Single pass
Space: O(n) - Hash map storage
"""
seen = {} # num -> index
for i, num in enumerate(nums):
complement = target - num
if complement in seen:
return [seen[complement], i]
seen[num] = i
return [] # No solution found
# Test your solution
if __name__ == "__main__":
nums = [2, 7, 11, 15]
target = 9
result = two_sum(nums, target)
print(f"Result: {result}") # [0, 1]`;
document.getElementById('codeEditor').value = solution;
alert('✨ Solution revealed! Study the pattern and try to implement it yourself next time.');
}
</script>
</body>
</html>
機能:
- インタラクティブなコードエディター
- リアルタイムのテスト実行
- 段階的なヒント
- テスト結果の視覚化
- パターンバッジ
- 進捗の追跡
対応言語
Python
# Hash Map pattern
def two_sum(nums: List[int], target: int) -> List[int]:
seen = {}
for i, num in enumerate(nums):
complement = target - num
if complement in seen:
return [seen[complement], i]
seen[num] = i
return []
TypeScript
// Hash Map pattern
function twoSum(nums: number[], target: number): number[] {
const seen = new Map<number, number>();
for (let i = 0; i < nums.length; i++) {
const complement = target - nums[i];
if (seen.has(complement)) {
return [seen.get(complement)!, i];
}
seen.set(nums[i], i);
}
return [];
}
Kotlin
// Hash Map pattern
fun twoSum(nums: IntArray, target: Int): IntArray {
val seen = mutableMapOf<Int, Int>()
nums.forEachIndexed { i, num ->
val complement = target - num
if (seen.containsKey(complement)) {
return intArrayOf(seen[complement]!!, i)
}
seen[num] = i
}
return intArrayOf()
}
Swift
// Hash Map pattern
func twoSum(_ nums: [Int], _ target: Int) -> [Int] {
var seen = [Int: Int]()
for (i, num) in nums.enumerated() {
let complement = target - num
if let j = seen[complement] {
return [j, i]
}
seen[num] = i
}
return []
}
問題の難易度の進み方
レベル1:基礎(易しい)
- 配列と文字列
- 基本的なハッシュマップ
- シンプルな2ポインター
- 線形探索 目標: 自信をつけ、構文を学ぶ
レベル2:パターン認識(易しい〜中級)
- スライディングウィンドウ
- 発展的な2ポインター
- 高速・低速ポインター
- 基本的な木 目標: パターンを認識する
レベル 3:コアアルゴリズム(中級)
- BFS と DFS
- 二分探索の応用
- 基本的な DP
- ヒープ 目標: よく使われるパターンを習得します
レベル 4:高度なテクニック(中級〜上級)
- 高度な DP
- グラフアルゴリズム
- バックトラッキング
- トライ 目標: 複雑なシナリオに対応します
レベル 5:面接準備完了(上級)
- システム設計との統合
- 最適化問題
- 複雑な DP
- 高度なグラフ 目標: あらゆる面接を突破します
教える学習テクニック
1. パターン認識
See problem → Identify pattern → Apply template → Optimize
2. 時間・空間計算量の分析
Always analyze:
- Time complexity: O(?)
- Space complexity: O(?)
- Can we do better?
3. テスト駆動開発
1. Read problem
2. Write test cases
3. Think of edge cases
4. Code solution
5. Run tests
6. Optimize
4. 最適化の進め方
Brute Force → Identify bottleneck → Apply pattern → Optimize space
5. 面接でのコミュニケーション
- State assumptions
- Ask clarifying questions
- Think out loud
- Explain trade-offs
- Discuss alternatives
参考資料
すべて /references に含まれています:
- patterns.md - テンプレート付きの必須パターン 20 種
- data_structures.md - 配列、連結リスト、木、グラフ、ヒープ
- problem_templates.md - 各パターンのコードテンプレート
- complexity_guide.md - Big O の分析と最適化
スクリプト
すべて /scripts にあります:
- generate_playground.sh - インタラクティブなコーディング環境を作成
- generate_problem.sh - 特定の問題タイプを生成
- generate_session.sh - 練習セッション全体を作成
ベストプラクティス
すべきこと:
✅ まずは力任せの解法から始め、その後最適化する ✅ 先にテストケースを書く ✅ 時間・空間計算量を分析する ✅ 同じパターンを何度も練習する ✅ アプローチを声に出して説明する ✅ 実際のプロダクトの文脈を活用して覚える ✅ 面接で使用する言語でコーディングする
してはいけないこと:
❌ すぐに最適解へ飛びつく ❌ 計算量の分析を省略する ❌ 理解せずに解法を暗記する ❌ 簡単な問題だけを練習する ❌ エッジケースを無視する ❌ 黙ってコーディングする(説明する練習をする) ❌ 1 回の挑戦で諦める
ゲーミフィケーション
実績システム
- 🌟 パターンマスター:同じパターンで 10 問を解く
- 🔥 連続記録:7 日連続で取り組む
- ⚡ スピードデーモン:15 分未満で解く
- 🎯 一発合格:初回の挑戦ですべてのテストに合格する
- 🏆 100 クラブ:100 問を解く
- 💎 最適化:O(n²) から O(n) に改善する
- 🧠 ヒントなし:ヒントを使わずに解く
進捗状況の追跡
- 難易度別に解いた問題数
- 習得したパターン
- 練習した言語
- 成功率
- 問題ごとの平均時間
- 連続記録カウンター
まとめ
このスキルは、次の方法で技術面接の準備を変革します:
- 実際のプロダクトの文脈 - 実践的なシナリオを通じて学ぶ
- パターン認識 - 必須の 20 パターンを習得する
- 複数言語対応 - Python、TypeScript、Kotlin、Swift で練習する
- インタラクティブ - ブラウザー上で即時フィードバックを受けながらコーディングする
- 段階的な学習 - 基礎からエキスパートレベルまで積み上げる
- 楽しい学習 - 実績と進捗状況の追跡を取り入れたゲーミフィケーション
- 実践的 - 実際の面接で役立つテクニック
「パターンを習得し、面接を突破しましょう。」 🚀
使い方: 練習したいパターン、難易度、または実際のプロダクトのシナリオを指定すると、すぐにインタラクティブなコーディング環境が用意されます!