LeetCode, solved in a notebook.

A JupyterLab extension that turns any LeetCode question into a notebook. Write the solution, run the examples, and submit from the toolbar.

pip install jupyterlab-leetcode
1.two-sum.ipynb
1. Two Sum

Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.

EasyArrayHash Table
from typing import List
class Solution:
    def twoSum(self, nums: List[int], target: int) -> List[int]:
        seen = {}
        for i, n in enumerate(nums):
            if target - n in seen:
                return [seen[target - n], i]
            seen[n] = i
s = Solution()
s.twoSum(nums=[2, 7, 11, 15], target=9)
[0, 1]
Press Submit to see what lands in the notebook.

No login screen. Use the browser you already have.

Open the LeetCode launcher in JupyterLab and pick the browser where you're already signed in to leetcode.com. The extension reads your LeetCode session cookie from that browser. It never sees or stores your password.

On macOS the system may ask for your keychain password the first time. This lets the extension read the browser's cookie store. You can choose "Always Allow".

  • Chrome
  • Firefox
  • Edge
  • Arc
  • Brave
  • Opera
  • Opera GX
  • Vivaldi
  • Chromium
  • LibreWolf
  • Safari

Find the next question without switching tabs.

Search by keyword, then filter by difficulty, status, topic, or company. Company filters need LeetCode Premium. Your profile, solved counts, and submission heatmap are on the same page.

Example question list as it appears in JupyterLab
#TitleDifficultyAcceptance
βœ“1Two Sum
Array, Hash Table
Easy55.8%Open notebook
3Longest Substring Without Repeating Characters
Hash Table, String, Sliding Window
Medium36.9%Open notebook
4Median of Two Sorted Arrays
Array, Binary Search, Divide and Conquer
Hard43.1%Open notebook
βœ“21Merge Two Sorted Lists
Linked List, Recursion
Easy66.4%Open notebook
Easy
548
Medium
701
Hard
119
Submission heatmap, filled in from your LeetCode profile

Every question becomes a notebook you keep.

Click a question and the extension writes a ready-to-run .ipynb next to your other work. Notebooks are grouped in folders of fifty. Your solutions stay on disk and can go in git.

your-workspace/
β”œβ”€ 1-50/
β”‚  β”œβ”€ 1.two-sum.ipynb
β”‚  β”œβ”€ 2.add-two-numbers.ipynb
β”‚  └─ 21.merge-two-sorted-lists.ipynb
β”œβ”€ 51-100/
β”‚  └─ 70.climbing-stairs.ipynb
└─ 201-250/
   └─ 206.reverse-linked-list.ipynb
  • descriptionThe question, its difficulty, topic tags, hints, and a link back to LeetCode.
  • solutionThe Python 3 starter code. Add more solution cells when you want another approach. Submit sends the last one.
  • examplesOne cell per example test case. LeetCode's null, true, and false are already converted to Python.

Submit, and the verdict is written into the notebook.

The Submit button saves the notebook and sends your solution to LeetCode. When judging finishes, the result is written to a cell at the end of the notebook. The full result is also saved in the notebook's metadata.

  • Accepted with runtime, memory, and how they rank against other submissions
  • Wrong Answer with the failing input, your output, and the expected output
  • Time Limit Exceeded with the last test case and how many passed
  • Runtime Error with the error and the input that caused it

Troubleshooting

The LeetCode panel doesn't appear in JupyterLab

Check that the frontend extension is installed:

jupyter labextension list
The panel appears but questions don't load

Check that the server extension is enabled, then restart JupyterLab:

jupyter server extension list
It says my browser has no LeetCode cookie

Sign in to leetcode.com in that browser, then choose it again. Safari isn't supported because it doesn't allow other apps to read its cookies.

Where are my notebooks saved?

In the folder JupyterLab was started from, under folders like 1-50/ and 51-100/.

How do I uninstall it?
pip uninstall jupyterlab-leetcode
pip install jupyterlab-leetcode