This guide explains how to add new LeetCode problems to this repository.
- Create a JSON file for your problem
- Run the generator script
- Commit your changes
Create a new JSON file in the problems/ directory following this naming convention:
problems/XXX-problem-name.json
Where XXX is the 3-digit problem number (e.g., 001, 042, 347).
Use this template for your problem:
{
"number": 1,
"title": "Two Sum",
"difficulty": "easy",
"description": {
"en": "Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.",
"zh-CN": "给定一个整数数组 nums 和一个整数目标值 target,请你在该数组中找出和为目标值 target 的那两个整数。",
"zh-TW": "給定一個整數陣列 nums 和一個整數目標值 target,請你在該陣列中找出和為目標值 target 的那兩個整數。",
"ja": "整数配列 nums と整数 target が与えられたとき、合計が target になる 2 つの数値のインデックスを返します。",
"es": "Dado un array de enteros nums y un entero target, devuelve los índices de los dos números que suman target.",
"de": "Gegeben ein Array von Ganzzahlen nums und eine Ganzzahl target, gib die Indizes der zwei Zahlen zurück.",
"fr": "Étant donné un tableau d'entiers nums et un entier target, renvoyez les indices des deux nombres."
},
"aplSolution": "TwoSum ← {\n ⍝ ⍺: target sum, ⍵: array\n indices ← ⍸⍺=+/∘.,⍨⍵\n 2↑indices\n}",
"explanation": {
"en": "Uses outer product operator ∘. to generate all possible pair sums.",
"zh-CN": "使用外积操作符 ∘. 生成所有可能的数对和。",
"zh-TW": "使用外積運算子 ∘. 生成所有可能的數對和。",
"ja": "外積演算子 ∘. を使用してすべての可能なペア和を生成します。",
"es": "Utiliza el operador de producto exterior ∘. para generar todas las sumas posibles.",
"de": "Verwendet den äußeren Produktoperator ∘. um alle möglichen Paarsummen zu generieren.",
"fr": "Utilise l'opérateur de produit extérieur ∘. pour générer toutes les sommes possibles."
},
"timeComplexity": "O(n²)",
"spaceComplexity": "O(n²)"
}number: Problem number (integer)title: Problem title in English (string)difficulty: One of: "easy", "medium", "hard" (string)description: Object with descriptions in 7 languagesaplSolution: APL code solution (string, use\nfor line breaks)explanation: Object with explanations in 7 languagestimeComplexity: Big O notation (string)spaceComplexity: Big O notation (string)
Add your problem to problems/index.json:
[
{
"number": 1,
"file": "001-two-sum.json"
},
{
"number": 2,
"file": "002-add-two-numbers.json"
}
]Keep the list sorted by problem number.
Run the generator script:
python3 generate_static_readmes.pyThis will:
- Create a directory for your problem:
problems/XXX-problem-name/ - Generate 7 language README files in that directory
- Update all
PROBLEMS_INDEX.*.mdfiles
Check that the following were created:
problems/XXX-problem-name/README.md(and 6 other language files)- Your problem appears in all
PROBLEMS_INDEX.*.mdfiles
git add problems/XXX-problem-name.json
git add problems/XXX-problem-name/
git add problems/index.json
git add PROBLEMS_INDEX*.md
git commit -m "Add problem #XXX: Problem Name"
git pushAPL is known for brevity. Try to capture the essence of the algorithm.
Use ⍝ for comments to explain your solution:
⍝ This is a comment
solution ← {⍵+1} ⍝ Increment by oneInclude usage examples in your solution:
MyFunction ← {
⍝ Implementation
}
⍝ Example usage
input ← 1 2 3 4 5
result ← MyFunction input
⍝ Result: 2 4 6 8 10If possible, test your APL code at TryAPL.org before submitting.
Common symbols you might need:
⍵- right argument (omega)⍺- left argument (alpha)⌽- reverse⍸- where (indices where true)∘.- outer product/- reduce⊂- enclose⊃- disclose/pick∇- del (recursive call)
- Clear and concise
- Follow LeetCode's style
- Include constraints if important
- Use DeepL, Google Translate, or ChatGPT for initial translations
- Have native speakers review if possible
- Keep technical terms consistent (e.g., "array" → "数组/陣列/配列")
- Two Sum, Reverse Linked List, Valid Palindrome
- Usually O(n) or O(log n) solutions
- Straightforward logic
- 3Sum, Maximum Subarray, Word Search
- May require O(n²) or dynamic programming
- More complex logic
- Trapping Rain Water, Median of Two Sorted Arrays
- Often O(n²) or worse, or complex algorithms
- Requires advanced techniques
- Create
problems/042-trapping-rain-water.json - Write your APL solution
- Add translations for all 7 languages
- Update
problems/index.json - Run
python3 generate_static_readmes.py - Commit and push!
- Check existing problems for examples
- Review the JSON schema above
- Open an issue on GitHub
- Test APL code at TryAPL.org
Happy problem solving! 🎉