Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
164 commits
Select commit Hold shift + click to select a range
134d20f
Converts to Python
retiman Mar 10, 2025
b8ab2ec
Updates to poetry 2.1.1
retiman Mar 10, 2025
8e3dab4
fix type issues
retiman Mar 10, 2025
8b0e7db
implements max stack
retiman Mar 10, 2025
b65ff1a
add task scheduler
retiman Mar 10, 2025
6aae54f
merge k sorte dlists
retiman Mar 10, 2025
74e7b28
updates binary search
retiman Mar 10, 2025
8341631
adds find peak element
retiman Mar 10, 2025
3560d99
removes the find peak element
retiman Mar 10, 2025
2f19695
find smallest divisor
retiman Mar 10, 2025
996b5fa
kth missing positive number
retiman Mar 10, 2025
cb5400f
kth smallest in sorted matrix
retiman Mar 10, 2025
254f31d
lis
retiman Mar 10, 2025
03ac22d
median of 2 sorted arrays
retiman Mar 10, 2025
7888769
searching in rotated array
retiman Mar 10, 2025
1e509fe
search in rotated
retiman Mar 10, 2025
11e4af0
make more pythonistic
retiman Mar 10, 2025
28536af
arithmetic slices ii
retiman Mar 11, 2025
9d34291
update docs
retiman Mar 11, 2025
bcbbf32
max subarray sum
retiman Mar 11, 2025
ea0f141
adds word break i
retiman Mar 11, 2025
dc2e3e2
add to make degrees even
retiman Mar 12, 2025
b3a1e30
switch linters
retiman Mar 12, 2025
bd3364a
update linting
retiman Mar 12, 2025
dbc3f8f
Automatic commit via GitHub Actions
Mar 12, 2025
a3b2de1
only use import
retiman Mar 12, 2025
7faa00b
lint first
retiman Mar 12, 2025
f98e001
all ours
retiman Mar 12, 2025
fd5648d
fixes importing
retiman Mar 12, 2025
077503a
very silly stuff
retiman Mar 12, 2025
0f72820
word search 2
retiman Mar 13, 2025
ac2a4ed
Automatic commit via GitHub Actions
Mar 13, 2025
2f4d60a
updated
retiman Mar 13, 2025
7e9192c
Merge branch 'adhoc/python' of https://github.com/retiman/leetcode in…
retiman Mar 13, 2025
25ad8d9
sort first
retiman Mar 13, 2025
3bdb386
Automatic commit via GitHub Actions
Mar 13, 2025
7bf09da
this ... works?
retiman Mar 13, 2025
f16408e
word search i
retiman Mar 13, 2025
a04ea68
delete it
retiman Mar 13, 2025
d64f42b
Merge branch 'adhoc/python' of https://github.com/retiman/leetcode in…
retiman Mar 13, 2025
037f326
add this
retiman Mar 13, 2025
4e3930b
removed
retiman Mar 13, 2025
eccaa41
nested weight list 2
retiman Mar 13, 2025
9c5f39a
updated docstrings
retiman Mar 13, 2025
ccd0fe8
docstrings
retiman Mar 13, 2025
03b7bba
docs
retiman Mar 13, 2025
004a547
parallel job scheduling
retiman Mar 14, 2025
a27732d
do not reformat the world
retiman Mar 14, 2025
c73cece
num islands
retiman Mar 14, 2025
f3b51d2
shortest path in a binary matrix
retiman Mar 14, 2025
34286e1
smallest int
retiman Mar 14, 2025
c48b19a
comments
retiman Mar 14, 2025
f36a5c5
update the readme
retiman Mar 15, 2025
c74b767
list interval intersections
retiman Mar 15, 2025
0e7f2fc
deletions
retiman Mar 15, 2025
ee9b372
Merge branch 'adhoc/python' of https://github.com/retiman/leetcode in…
retiman Mar 15, 2025
883bff6
fixed bug
retiman Mar 15, 2025
3543551
meeting rooms
retiman Mar 15, 2025
4b71a11
simulate max heap
retiman Mar 15, 2025
17fe32c
renames
retiman Mar 15, 2025
64258f6
meeting scheduler
retiman Mar 15, 2025
956e078
meeting scheduler
retiman Mar 15, 2025
0a16aff
deletes the meeting scheduler test
retiman Mar 15, 2025
5701228
merge intervals test
retiman Mar 15, 2025
ce65f79
appears to do nothing
retiman Mar 15, 2025
bcb3672
adds two numbers
retiman Mar 15, 2025
d24aadc
all one
retiman Mar 16, 2025
e6ba6e8
copy list with random pointers
retiman Mar 16, 2025
ccd8068
lru cache
retiman Mar 16, 2025
7a8d267
merge 2 sorted lists
retiman Mar 16, 2025
80c541f
remove nth node
retiman Mar 16, 2025
4de544e
number of one bits set
retiman Mar 16, 2025
255de76
power of 2
retiman Mar 16, 2025
15e25d9
removes ts
retiman Mar 16, 2025
5c8b9e5
reverse integer
retiman Mar 16, 2025
aafc84a
rotate image
retiman Mar 16, 2025
2824079
sequential digits
retiman Mar 16, 2025
b72348e
robot
retiman Mar 16, 2025
6744677
matrix
retiman Mar 16, 2025
856dbd8
replacements
retiman Mar 16, 2025
05f7560
add diff
retiman Mar 16, 2025
db42db0
add diff
retiman Mar 16, 2025
9b55e0e
hard questions
retiman Mar 16, 2025
0d388c3
subarray sum
retiman Mar 17, 2025
62ce508
prefix sum
retiman Mar 17, 2025
70ee0ac
Automatic commit via GitHub Actions
Mar 17, 2025
16bc336
max sum
retiman Mar 17, 2025
86bfa4b
Merge branch 'adhoc/python' of https://github.com/retiman/leetcode in…
retiman Mar 17, 2025
5bd05bb
prefix usm
retiman Mar 17, 2025
899ee0c
random pick with weight
retiman Mar 17, 2025
c53c70c
deletes random pick
retiman Mar 17, 2025
5b7341f
rangesum
retiman Mar 17, 2025
2bfedb4
subarray sum
retiman Mar 17, 2025
b55355b
max operations
retiman Mar 17, 2025
02721e7
optimnal
retiman Mar 17, 2025
34f1b73
permutations
retiman Mar 17, 2025
460142e
subsets
retiman Mar 17, 2025
6f3e734
subsets
retiman Mar 17, 2025
4a308db
word break 2
retiman Mar 18, 2025
eb500c6
best time
retiman Mar 18, 2025
518751f
count subarrays
retiman Mar 18, 2025
2fe3027
length of longest
retiman Mar 18, 2025
83fb64d
ongest continuous
retiman Mar 18, 2025
6d43bd2
max sum
retiman Mar 18, 2025
05fc4a6
min window substr
retiman Mar 18, 2025
551195a
moving avg
retiman Mar 18, 2025
f29fb80
repeated dna
retiman Mar 18, 2025
b033ae4
basic calc 2
retiman Mar 18, 2025
94ad5de
kv store
retiman Mar 18, 2025
0094cc7
kv store
retiman Mar 18, 2025
d65370c
longest abs filepath
retiman Mar 18, 2025
faba123
max to make sorted
retiman Mar 18, 2025
83e53be
min_stack
retiman Mar 18, 2025
f65d55f
min add
retiman Mar 18, 2025
1cd3859
min remove
retiman Mar 18, 2025
c981732
valid parens
retiman Mar 18, 2025
5647e7d
valid num
retiman Mar 18, 2025
ad736fb
fixed
retiman Mar 18, 2025
bfd60b2
simplify path
retiman Mar 18, 2025
b0329d6
tmp
retiman Mar 19, 2025
9f0237b
closest palindrome
retiman Mar 19, 2025
5168cbb
int2roman
retiman Mar 19, 2025
eb46c95
roman2int
retiman Mar 19, 2025
f0a0c08
why make me type pycache windows?
retiman Mar 19, 2025
070468e
english
retiman Mar 19, 2025
5b934b8
update lock
retiman Mar 19, 2025
1750793
letters
retiman Mar 19, 2025
3e23573
rename to mapping
retiman Mar 19, 2025
6dcf3e7
letter combs
retiman Mar 19, 2025
985a20a
hybrid
retiman Mar 19, 2025
51f1282
graph
retiman Mar 19, 2025
aa160b1
comments
retiman Mar 19, 2025
b69cae1
longest
retiman Mar 19, 2025
b80cd03
palindrome num
retiman Mar 19, 2025
3d4f8fe
remove duples
retiman Mar 19, 2025
d073c59
remove duples
retiman Mar 19, 2025
ab090c3
remove
retiman Mar 19, 2025
09a1300
reverse words
retiman Mar 19, 2025
4be13ca
time to rearrange
retiman Mar 19, 2025
3508ea9
vowel checker
retiman Mar 19, 2025
0fbbd28
level order traversal
retiman Mar 20, 2025
69665b5
right side view
retiman Mar 20, 2025
1ad57a5
binary tree vertical
retiman Mar 20, 2025
5a78c38
construct quad tree
retiman Mar 20, 2025
ea6cb0f
in mem fs
retiman Mar 20, 2025
1ee9897
fs
retiman Mar 20, 2025
0b8b4d4
diameter
retiman Mar 20, 2025
0c9ff35
lca
retiman Mar 20, 2025
ba4407a
lca 3
retiman Mar 20, 2025
f8bbebc
range sum
retiman Mar 20, 2025
ab9276a
tree problems
retiman Mar 20, 2025
e3dbb90
most water
retiman Mar 20, 2025
9c7f138
longest
retiman Mar 20, 2025
a4cf86b
remove dupes
retiman Mar 20, 2025
92b5f65
remove elements
retiman Mar 20, 2025
7b198a2
str comp
retiman Mar 20, 2025
47f9573
3sum closest
retiman Mar 20, 2025
113e5cc
3sum
retiman Mar 20, 2025
d594a04
trapping
retiman Mar 20, 2025
dd81d67
2sum
retiman Mar 20, 2025
502f84f
valid 2
retiman Mar 20, 2025
7f52d4e
Automatic commit via GitHub Actions
Mar 20, 2025
f8c63f8
triangle
retiman Mar 20, 2025
25f4e33
Merge branch 'adhoc/python' of https://github.com/retiman/leetcode in…
retiman Mar 20, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
10 changes: 4 additions & 6 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
# Setting this to true makes VSCode break typing flow. The following ticket mentions that Intellisense dropdowns
# disappear, and that is presumably fixed. However, if you aren't, then the cursor still jumps and typing flow is still
# broken.
#
# See https://github.com/editorconfig/editorconfig-vscode/issues/40
# insert_final_newline = true
insert_final_newline = true
trim_trailing_whitespace = true

[*.py]
indent_size = 4
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* text=auto eol=lf
* text eol=lf
31 changes: 22 additions & 9 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: Build and Test
on:
pull_request:
paths-ignore:
- CODEOWNERS
- LICENSE
- README.md
push:
Expand All @@ -27,19 +28,31 @@ jobs:
ref: ${{ github.head_ref }}
token: ${{ steps.generate-token.outputs.token }}

- name: Setup NodeJS
uses: actions/setup-node@v3
- name: Setup Python
uses: actions/setup-python@v5
with:
node-version: 20
python-version: '3.13'

- name: Install poetry
run: python -m pip install poetry==2.1.1

- name: Configure poetry
run: poetry config virtualenvs.in-project true

- name: Cache the virtualenv
uses: actions/cache@v4
with:
path: ./.venv
key: ${{ runner.os }}-venv-${{ hashFiles('**/poetry.lock') }}

- name: Install dependencies
run: npm ci
run: poetry install

- name: Fix
run: npm run fix
- name: Run format
run: poetry run format

- name: Build
run: npm run build
- name: Run lint
run: poetry run lint

- name: Commit
if: ${{ github.ref != 'refs/heads/main' }}
Expand All @@ -52,4 +65,4 @@ jobs:

- name: Test
if: ${{ steps.commit.outputs.committed == 'false' }}
run: npm run test
run: poetry run test
12 changes: 8 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
__pycache__/
.env/
.mypy_cache/
.venv/
.vscode/
build/
coverage/
dist/
node_modules/

*.tgz
.env
*.egg-info/
*.pyc
*.pyo
18 changes: 0 additions & 18 deletions .prettierignore

This file was deleted.

3 changes: 0 additions & 3 deletions .vscode/settings.json

This file was deleted.

39 changes: 4 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,8 @@

Problems and solutions for LeetCode.

## Development

## Priority Queue

Several problems require access to a priority queue; however, TypeScript itself does not have such a built-in data structure.


### LeetCode

LeetCode provides support for [heaps](https://support.leetcode.com/hc/en-us/articles/360011833974-What-are-the-environments-for-the-programming-languages) via [datastructures-js/priority-queue](https://github.com/datastructures-js/priority-queue) at version `5.4.0`. This is the library used, because this repository is for LeetCode submissions.

A couple of gotchas for version `5.4.0` that don't exist in later versions:

- LeetCode uses `require` style imports and not `import`. Practically that means `MaxPriorityQueue` and `MinPriorityQueue` do not accept parameterized types.
- Also, `MaxPriorityQueue` and `MinPriorityQueue` are exported as values. To get the type, do `InstanceType<typeof MaxPriorityQueue>`.
- Primitives are wrapped. That is, if you do `heap.enqueue(1)`, then you should `heap.dequeue().element` to get `1` back.
- Objects are not wrapped. That is, if you do `heap.enqueue(foo)`, then you should do `heap.dequeue()` to get `foo` back, if `foo` is an object.


### CoderPad

CoderPad has no official support for priority queues.


### CodeSignal

CodeSignal's official documentation does not claim support for priority queues. However, there is [documentation](https://learn.codesignal.com/preview/lessons/3525/heaps-and-priority-queues-in-javascript?utm_source=chatgpt.com) suggesting that [heap-js](https://github.com/ignlg/heap-js) is available.


### Other

There are a few other options.

- Insert into an array and sort it afterwards. See [simple-heap.ts](src/heap/simple-heap.ts).
- Use binary search to insert into an array and do not sort. See [bs-search-heap.ts](src/heap/bs-search-heap.ts).
- Roll your own heap during the interview. You beast.
- Give up.
1. Install poetry: `curl -sSL https://install.python-poetry.org | python`
1. Install dependencies: `poetry install`
1. Run tests: `poetry run test`
153 changes: 0 additions & 153 deletions eslint.config.mjs

This file was deleted.

Loading