🐐
LeetGoat
Interview Prep
Competitive Programming
Discord
Union Find Picker
Range queries
2D range queries
Sets
Union find
Strings
Tree queries
Tree helpers
Graphs
Matrices
Math
Primes
Bit ops & Bitset
Geometry
Misc.
Golden References
Unselect all
Union
unite
(i, j)
Merge i's and j's components
Undo / remove
rollbackLastUnion
()
Undo the most recent unite, even one that merged nothing
removeEdge
(i, j)
Delete one edge between i and j: its component can split in two
Queries
areUnioned
(i, j)
Are i and j in the same component
size
(i)
How many elements are in i's component
numComponents
()
How many components there are
largestSize
()
Size of the biggest component
find
(i)
The representative (root) of i's component
parent
(i)
i's parent pointer, to walk the merge tree yourself (only in union finds without path compression)
elementsInGroup
(i)
Every element in i's component
groups
()
One list per component, e.g. [[10, 30], [20, 40]]
sizes
()
Every component's size, biggest first
roots
()
One representative per component
Per component
componentSum
(i)
Sum of the values in i's component
componentMin
(i)
Smallest value in i's component
componentMax
(i)
Largest value in i's component
componentData
(i)
Your own Node per component: fill in baseFn and combine, like the generic seg tree
Elements
add
(val)
A new element in its own component (you can start empty)
Remove-only set (starts full)
remove
(x)
Remove x; 1 if it was there, else 0
smallestGteX
(x)
Smallest value ≥ x still in the set, from any x
smallestGtX
(x)
Smallest value > x still in the set, from any x
largestLteX
(x)
Largest value ≤ x still in the set, from any x
largestLtX
(x)
Largest value < x still in the set, from any x
contains
(x)
Is x still in the set
popInValRange
(lo, hi)
Remove every value in [lo, hi] and return them in order
min
()
Smallest value still in the set
max
()
Largest value still in the set
popMin
()
Remove and return the smallest value
popMax
()
Remove and return the largest value