For a Uniswap Labs platform conversation, use integer tick boundaries to show how a liquidity view changes as it crosses positions. Then discuss the block at which your result is valid.
What to prepare for Uniswap
Uniswap Labs lists its openings on its official careers site. The protocol documentation explains positions that apply in selected price ranges. This original mock checks range accounting in an analytics projection and does not simulate swaps or return a trading quote. Uniswap Labs job listings, Uniswap liquidity documentation
Sweep active liquidity over tick ranges
Positions carry integer lower and upper ticks and nonnegative weight. Each is active for lower ≤ tick < upper, with lower < upper. Given query ticks, return the sum of active weights for each tick in original order.
from collections import Counter
def active(positions, ticks):
delta = Counter()
for low, high, weight in positions:
delta[low] += weight
delta[high] -= weight
boundaries = sorted(delta)
out = [0] * len(ticks)
total = j = 0
for i, tick in sorted(enumerate(ticks), key=lambda p: p[1]):
while j < len(boundaries) and boundaries[j] <= tick:
total += delta[boundaries[j]]
j += 1
out[i] = total
return out
assert active([(0, 4, 2), (4, 8, 7), (2, 6, 3)], [8, 4, 0, 2, 6]) == [0, 10, 2, 5, 7]
assert active([], [-1, 0]) == [0, 0]
assert active([(0, 1, 3)], []) == []
Store signed deltas at lower and upper. Sort boundaries and queries, then fold deltas up through each queried tick. Same-tick positions combine. Runtime is O((p+q)log(p+q)) and space O(p+q). At an upper boundary remove its weight before recording the query.
Walk through a boundary case
For a position [0,4) with weight two and [4,8) with weight seven, crossing tick 4 removes two and adds seven. Add [2,6) with weight three and the active value at 4 becomes ten. Test the same tick in two projection versions, one including a retracted block. Reversal should return every touched delta to the exact prior value, including removing zero-valued keys.
Apply then reverse a block's projection changes
The state is a map of per-tick liquidity deltas. Use a signed journal to apply or reverse a synthetic block. Clean up zero positions in the projection so exact state comparisons are possible. Add a meaningful test where a retracted event shares a boundary with a retained position.
def journal(current, changes, direction):
result = current.copy()
for tick, delta in changes:
result[tick] = result.get(tick, 0) + direction * delta
if result[tick] == 0:
del result[tick]
return result
initial = {0: 3, 5: -3}
block = [(5, 7), (9, -7)]
applied = journal(initial, block, 1)
assert applied == {0: 3, 5: 4, 9: -7}
assert journal(applied, block, -1) == initial
Design and debugging follow-up
A chain indexer reports a result based on a head block that later changes. Bind results to block hash and expose whether the state is provisional under your chosen policy. On a reorganization, rewind affected deltas and replay replacement blocks before serving an updated answer. Test rollback with one added position and one removed position.
What to bring to a mock interview
Prepare an abstraction story that distinguishes protocol math from the UI. Explain the exact positions and block state consumed by a fixture before comparing calculated values.