leetcode api
npm install @codingsnack/leetcode-apinpm i @codingsnack/leetcode-api
yarn add @codingsnack/leetcode-api
js
const { Leetcode } = require('@codingsnack/leetcode-api');
const main = async () => {
// csrfToken after you've logged in
const csrfToken = '';
// LEETCODE_SESSION after you've logged in
const session = '';
const lc = new Leetcode({ csrfToken, session });
const problem = await lc.getProblem('two-sum');
console.log(problem);
};
main();
`
Available methods
Currently availably methods are
- getProblem(slug): Get information about single problem based on its title(also referred to as slug)
- getMyLists(): Get all the lists that you have created or have favorited.
- getProblems(params): Get all the problems based on passed params. Supports pagination, filter by category, listId, difficulty, status, premiumOnly, tags, companies, searchKeyWords. You can also orderBy FRONTEND_ID, AC_RATE(acceptance rate), DIFFICULTY, FREQUENCY. Sort order can be ascending or descending. This is same as going to .
- getSubmission(slug): Get all submissions for given problem.
- getRandomQuestion(): Get a random question.
- getPublicList(listId): Get a public list based on its listId.
- getProblemsByTag(tag): Get problems by tag(like array). This is same as going to .
- getProblemsByCompany(company): Get problems by company(like apple). This is same as going to .
- getSimilarProblems(slug, depth = 1): Get similar problems based on slug. Depth param is optional and default value is 1. If depth is say 2 and slug is two-sum, then this will fetch similar questions to two-sum and then similar questions to all the similar questions of two-sum. Note that this will return a problem instance and this will have a field called similarProblems which is an array and the consumer can recurse through this. Also note that this method is still in beta.
- addQuestionToFavorite(favoriteSlug, questionSlug): Add a question to a favorite list. Returns an object with ok (boolean) and error (string) properties.
- batchAddQuestionsToFavorite(favoriteSlug, questionSlugs): Add multiple questions to a favorite list. Returns an object with ok (boolean) and error` (string) properties.