@tomrm/leetcode-utils
v1.0.1
Published
utility library for fetching leetcode problems.
Readme
@tomrm/leetcode-utils
A TypeScript utility library for building LeetCode problem randomisers. Contains a complete, enriched problem dataset with topic tags, and helper functions for filtering and selection.
Installation
npm install @tomrm/leetcode-utils
# or
yarn add @tomrm/leetcode-utilsFeatures
- 300+ LeetCode problems with difficulty and topic tags, sourced directly from the LeetCode GraphQL API
- Filter problems by difficulty and topic
- Zero dependencies
- Fully typed with TypeScript
Usage
Get all problems
import { getProblems } from '@tomrm/leetcode-utils'
const problems = getProblems()
// [{ id: '1', title: 'Two Sum', difficulty: 'EASY', topics: ['Array', 'Hash Table'], titleSlug: 'two-sum' }, ...]Get a random problem
import { getRandomProblem } from '@tomrm/leetcode-utils'
// No history — pick any problem
const problem = getRandomProblem([])
// Pass history to exclude the last 2 problems
const problem = getRandomProblem(history)Filter problems
import { getProblems } from '@tomrm/leetcode-utils'
const problems = getProblems().filter(p =>
p.difficulty === 'MEDIUM' &&
p.topics.includes('Graph')
)API
getProblems(): Problem[]
Returns the full list of problems.
getRandomProblem(): Problem | undefined
Returns a random problem. Returns undefined if no problems are available.
Types
type Difficulty = 'EASY' | 'MEDIUM' | 'HARD'
interface Problem {
id: string
title: string
titleSlug: string
difficulty: Difficulty
topics: string[]
}Data
The problem dataset is sourced from the LeetCode GraphQL API and bundled at build time — there is no runtime API dependency.
License
MIT
