Skip to content

Instantly share code, notes, and snippets.

View asjadsyed's full-sized avatar
🧑‍💻

Asjad Syed asjadsyed

🧑‍💻
View GitHub Profile
@asjadsyed
asjadsyed / ceil_div.py
Last active April 14, 2024 07:26
Ceiling Division
def ceil_div(n, d): return -(n // -d)
def floor_div(n, d): return n // d
@asjadsyed
asjadsyed / union_find.py
Last active March 28, 2023 22:07
Union Find implementation with Path Compression and Union by Size
#!/usr/bin/env python3
from typing import Any, Dict, Iterable, Tuple
class UnionFind:
def __init__(self, vs: Iterable[Any] = (), es: Iterable[Tuple[Any, Any]] = ()) -> None:
self.parent: Dict[Any, Any] = {}
self.size: Dict[Any, int] = {}
for v in vs: