🐐
LeetGoat
Interview Prep
Competitive Programming
Discord
Set 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
Values are tuples
All values ever added known (offline, compressed)
All values ever added not known (online)
Unselect all
Add / remove
add
(x)
Add one copy of x
remove
(x)
Remove one copy of x (if present)
popMin
()
Remove and return the smallest value
popMax
()
Remove and return the largest value
pop
(i)
Remove and return the value at sorted position i, 0-indexed: pop(0) removes the min
clear
()
Empty it, to reuse instead of building a new one (no other op pays for this)
Uncommon
addCount
(val, cnt)
Add cnt copies of val
removeCount
(val, cnt)
Remove up to cnt copies of val
removeAll
(val)
Remove every copy of val
removeInValRange
(lo, hi)
Remove every value in [lo, hi]
xorAll
(y)
Replace every value v by v ^ y
shiftAll
(d)
Add d to every value (d may be negative)
Whole set
size
()
How many values (copies count)
min
()
Smallest value
max
()
Largest value
sumAll
()
Sum of all values
mode
()
(most frequent value, its count)
countDistinct
()
How many distinct values
mex
()
Smallest non-negative integer not in the set
Frequency
maxFreq
()
How many copies the most frequent value has
minFreq
()
How many copies the least frequent value has
valuesWithMaxFreq
()
Every value tied for the most copies
valuesWithMinFreq
()
Every value tied for the fewest copies
By rank
kth
(i)
Value at sorted position i, 0-indexed: kth(0) is the min, kth(size − 1) the max
Uncommon
firstIndex
(x)
Position of the first copy of x in sorted order (0-indexed), or -1 if x isn't in the set
lastIndex
(x)
Position of the last copy of x in sorted order (0-indexed), or -1 if x isn't in the set
By value
count
(x)
How many copies of x
countLtX
(x)
How many values < x
countLteX
(x)
How many values ≤ x
largestLtX
(x)
Largest value < x
largestLteX
(x)
Largest value ≤ x (floor)
smallestGtX
(x)
Smallest value > x
smallestGteX
(x)
Smallest value ≥ x (ceiling)
countGtX
(x)
How many values > x
countGteX
(x)
How many values ≥ x
countInValRange
(lo, hi)
How many values in [lo, hi]
countDistinctInValRange
(lo, hi)
How many distinct values in [lo, hi]
Sums
sumSmallestK
(k)
Sum of the k smallest values; k is a count: k = 0 → none (0), k = 1 → just the smallest
sumLargestK
(k)
Sum of the k largest values; k is a count: k = 0 → none (0), k = 1 → just the largest
sumLtX
(x)
Sum of the values < x
sumLteX
(x)
Sum of the values ≤ x
sumGtX
(x)
Sum of the values > x
sumGteX
(x)
Sum of the values ≥ x
sumInValRange
(lo, hi)
Sum of the values in [lo, hi]
sumKthSmallestRange
(kFrom, kTo)
Sum of the kFrom-th..kTo-th smallest values; 1-indexed ranks, inclusive: (1, 1) = the smallest, (2, 4) = 2nd..4th smallest
sumKthLargestRange
(kFrom, kTo)
Sum of the kFrom-th..kTo-th largest values; 1-indexed ranks, inclusive: (1, 1) = the largest, (5, 8) = 5th..8th largest
Median
medianLow
()
Lower median (the ⌈n/2⌉-th smallest)
medianHigh
()
Upper median (the (⌊n/2⌋+1)-th smallest)
sumAbsDiffToMedian
()
Σ|v − median|: min total moves to make all values equal
sumAbsDiffToX
(x)
Σ|v − x|: total moves to bring every value to x
Gaps
minAdjacentDiff
()
Smallest difference between two values (0 if some value repeats)
maxGap
()
Largest difference between neighbouring distinct values
▶
XOR of values
▶
OR of values
▶
AND of values
▶
gcd of values
▶
LCM of values (capped)
▶
XOR with x
▶
XOR with x, limit on v