Question API
The /api/question route serves a single coding challenge question from the
dataset. Questions can be filtered by ID, slug, difficulty, or topic tag.
When multiple questions match the filters a random one is returned, making the
endpoint suitable for powering randomised game sessions.
Code Battlegrounds - Question API (1.0.0)
Download OpenAPI specification:Download
REST endpoint for retrieving coding questions sourced from the LeetCode-style dataset (public/dataset.csv).
The dataset is loaded once at server start and cached in memory. Every call returns exactly one question object, chosen randomly from the questions that match the supplied filters.
Get a single coding question
Returns one question, picked at random from all questions that match the supplied filters. Omit all query parameters to receive a uniformly random question from the full dataset.
query Parameters
| id | integer Example: id=1 Numeric LeetCode-style Question ID (e.g. |
| slug | string Example: slug=two-sum URL slug of the question (e.g. |
| difficulty | string Enum: "Easy" "Medium" "Hard" Example: difficulty=Medium Filter by difficulty level (case-insensitive). |
| topic | string Example: topic=dynamic programming Partial, case-insensitive match against any topic tag on the
question (e.g. |
Responses
Response samples
- 200
- 404
- 405
- 500
{- "question": {
- "id": 0,
- "questionId": 1,
- "title": "Two Sum",
- "slug": "two-sum",
- "text": "Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.",
- "topics": [
- "Array",
- "Hash Table"
], - "difficulty": "Easy",
- "successRate": 48.5,
- "totalSubmissions": 13207990,
- "totalAccepted": 6403821,
- "likes": 31242,
- "dislikes": 988,
- "likeRatio": 0.969,
- "hints": [
- "A really brute force way would be to search for all possible pairs of numbers but that would be too slow."
], - "similarQuestionIds": [
- 15,
- 18,
- 167
], - "similarQuestionTitles": [
- "3Sum",
- "4Sum",
- "Two Sum II - Input Array Is Sorted"
]
}
}