Dataset Viewer
Auto-converted to Parquet Duplicate
messages
listlengths
2
4
[ { "role": "user", "content": "Design and implement an offline algorithm for dynamic connectivity in an undirected graph. The input is n and a sequence of operations add(u,v), remove(u,v), and connected(u,v); an edge may be added again after it has been removed, but duplicate active copies are forbidden, and...
[ { "role": "user", "content": "We need a reliable event-driven service. An API request changes our database and must eventually publish an event to a broker; consumers update their own databases. Network failures can happen at any point. Explain a design that avoids lost events and duplicate business effects...
[ { "role": "user", "content": "There are n distinguishable balls independently assigned uniformly to m distinguishable boxes. Let K be the total number of colliding pairs, counting every pair of balls in the same box; thus a box with j balls contributes binomial(j,2), even when j is at least 3. Derive an exa...
[ { "role": "user", "content": "Given a directed graph with nonnegative edge weights, return shortest distances from source s and one shortest path to every reachable vertex. Explain the heap invariant, stale entries, and the role of the weight restriction." }, { "role": "assistant", "content": "<...
[ { "role": "user", "content": "For a graph that may have negative edge weights, compute shortest distances from a source and identify which vertices are affected by reachable negative cycles. Give a proof-level description and complexity." }, { "role": "assistant", "content": "<|reason|>Any short...
[ { "role": "user", "content": "Shortest paths are needed in a directed graph whose edge weights are only 0 or 1. Give an algorithm faster than a binary heap and explain why deque ordering is valid." }, { "role": "assistant", "content": "<|reason|>A relaxation adds either zero or one to the curren...
[ { "role": "user", "content": "Return a topological ordering of a directed graph, or report that it contains a cycle. Include isolated vertices and state why the algorithm detects every cycle." }, { "role": "assistant", "content": "<|reason|>Kahn's algorithm repeatedly removes zero-indegree verti...
[ { "role": "user", "content": "Describe an O(V+E) method to find all strongly connected components (SCCs) and construct the condensation graph. Explain why the condensation is acyclic." }, { "role": "assistant", "content": "<|reason|>Tarjan's DFS maintains discovery indices, low-link values, and ...
[ { "role": "user", "content": "Find every bridge in an undirected multigraph. Explain how to avoid falsely treating a parallel edge as a bridge and give the low-link condition." }, { "role": "assistant", "content": "<|reason|>A DFS tree edge (v,w) is a bridge exactly when the subtree at w has no ...
[ { "role": "user", "content": "Give a criterion for whether a connected undirected weighted graph has a unique minimum spanning tree (MST), including tied edge weights. A simple ‘all weights distinct’ condition is too strong." }, { "role": "assistant", "content": "<|reason|>Process equal-weight e...
[ { "role": "user", "content": "Explain Dinic's maximum-flow algorithm, including residual reverse edges, level graphs, and when flow can be augmented. State a safe complexity bound for general capacities." }, { "role": "assistant", "content": "<|reason|>Residual reverse edges let later augmentati...
[ { "role": "user", "content": "For a flow network with integer costs that may be negative but has no negative-cost cycle reachable in the usable residual network, describe successive shortest augmenting path with potentials. Explain why raw Dijkstra is not initially valid." }, { "role": "assistant", ...
[ { "role": "user", "content": "Find a maximum matching in a bipartite graph efficiently. Explain the layered augmenting-path idea and why searching every augmenting path one at a time is slower." }, { "role": "assistant", "content": "<|reason|>Hopcroft–Karp finds a maximal set of shortest augment...
[ { "role": "user", "content": "Reduce a 2-SAT formula to graph reachability, test satisfiability, and explain what information SCCs provide. A clause has at most two literals." }, { "role": "assistant", "content": "<|reason|>Each clause `(a OR b)` is equivalent to implications `not a -> b` and `n...
[ { "role": "user", "content": "A Fenwick tree stores nonnegative integer frequencies. Design a method to find the smallest index whose prefix sum is at least k, in O(log n), and state its preconditions." }, { "role": "assistant", "content": "<|reason|>Fenwick binary lifting constructs the answer ...
[ { "role": "user", "content": "Implement range-add and range-minimum queries on an array in O(log n) per operation. Explain the lazy propagation invariant and what must happen before descending." }, { "role": "assistant", "content": "<|reason|>A node stores the minimum of its segment including al...
[ { "role": "user", "content": "For a static array, answer range-minimum queries in O(1) after preprocessing. Explain why overlapping sparse-table blocks are safe for minimum but not for every operation." }, { "role": "assistant", "content": "<|reason|>A query interval can be covered by two power-...
[ { "role": "user", "content": "Preprocess a rooted tree for lowest common ancestor queries. Give the binary-lifting recurrence, query method, and complexity." }, { "role": "assistant", "content": "<|reason|>Store `up[j][v]`, the ancestor 2^j edges above v. Every jump decomposes into powers of two...
[ { "role": "user", "content": "For each vertex v in a tree, compute the sum of distances from v to all vertices in O(n). Derive a rerooting formula from one DFS result." }, { "role": "assistant", "content": "<|reason|>Choose a root r. A postorder computes subtree sizes and the distance sum at r. ...
[ { "role": "user", "content": "State and use the degree conditions for a directed Euler trail, and describe how to construct the trail. Include the connectivity condition often omitted from degree-only tests." }, { "role": "assistant", "content": "<|reason|>Degree balance is necessary but does no...
[ { "role": "user", "content": "Given many patterns and a long text, report all pattern occurrences in O(text length + total pattern length + matches). Describe Aho–Corasick failure links and output handling." }, { "role": "assistant", "content": "<|reason|>The trie shares pattern prefixes; failur...
[ { "role": "user", "content": "Explain KMP for finding every occurrence of a pattern in a streaming text without backing up the text cursor. Define the prefix function and the mismatch transition." }, { "role": "assistant", "content": "<|reason|>The prefix function records the longest proper bord...
[ { "role": "user", "content": "Return a longest increasing subsequence (strictly increasing) in O(n log n), not just its length. Explain how parent pointers reconstruct one answer and how to handle duplicates." }, { "role": "assistant", "content": "<|reason|>Maintain the smallest ending value for...
[ { "role": "user", "content": "Find the maximum-sum subarray whose length is between L and R inclusive. Give an O(n) algorithm and explain the index window." }, { "role": "assistant", "content": "<|reason|>With prefix sums P, a subarray ending at i and valid length has sum `P[i]-P[j]` for `j in [...
[ { "role": "user", "content": "Maintain the median of a sliding window of integers under insertion and expiration in O(log w) amortized time. Explain why two ordinary heaps need extra bookkeeping." }, { "role": "assistant", "content": "<|reason|>A max-heap for the lower half and min-heap for the ...
[ { "role": "user", "content": "Support range addition and range-sum queries on a one-indexed array with two Fenwick trees. Derive the prefix-sum formula and update signs." }, { "role": "assistant", "content": "<|reason|>A difference array turns range addition into two point changes. The prefix su...
[ { "role": "user", "content": "Compute the convex hull of planar points in O(n log n), returning only extreme vertices and excluding collinear points along hull edges. State orientation and duplicate handling." }, { "role": "assistant", "content": "<|reason|>Sort and deduplicate points, then buil...
[ { "role": "user", "content": "Design an O(n log n) closest-pair algorithm for planar points. Explain how to retain the complexity when examining the vertical strip." }, { "role": "assistant", "content": "<|reason|>Divide by x-coordinate and recursively compute each half’s minimum distance. Merge...
[ { "role": "user", "content": "Given intervals with start, finish, and value, choose a maximum-value non-overlapping subset in O(n log n). Define how touching endpoints are treated." }, { "role": "assistant", "content": "<|reason|>Sort intervals by finish time. For interval i, the optimal solutio...
[ { "role": "user", "content": "Solve 0/1 knapsack and reconstruct a chosen item set. Explain how a one-dimensional value DP differs from reconstruction storage." }, { "role": "assistant", "content": "<|reason|>Each item must be used at most once, so capacities must be processed downward in the on...
[ { "role": "user", "content": "Compute the longest common subsequence (LCS) of two strings in O(mn) time but O(min(m,n)) working memory, and reconstruct an actual subsequence." }, { "role": "assistant", "content": "<|reason|>Hirschberg splits one string in half. Forward and reverse linear-space D...
[ { "role": "user", "content": "Give a weighted edit-distance recurrence with insertion, deletion, and substitution costs. Explain when the usual recurrence does not model transposition." }, { "role": "assistant", "content": "<|reason|>An optimal edit script’s last operation is insertion, deletion...
[ { "role": "user", "content": "Explain A* search for a shortest path and distinguish admissibility from consistency. What can an implementation safely do when a heuristic is admissible but inconsistent?" }, { "role": "assistant", "content": "<|reason|>Admissibility ensures the heuristic never ove...
[ { "role": "user", "content": "Design a cache-aside service for expensive database reads. It has multiple application replicas, bursts of identical requests, and occasionally stale data. Describe stampede prevention and invalidation tradeoffs." }, { "role": "assistant", "content": "<|reason|>Cach...
[ { "role": "user", "content": "Implement a token bucket rate limiter for a single API process and then explain how to make its state safe across many replicas." }, { "role": "assistant", "content": "<|reason|>A bucket stores available tokens and the last refill time. On each request, refill by el...
[ { "role": "user", "content": "Two doctors are on call; each transaction reads that at least one is on call and then may turn itself off. Under snapshot isolation, explain the anomaly and give two sound fixes." }, { "role": "assistant", "content": "<|reason|>Both transactions can read the same va...
[ { "role": "user", "content": "An API creates a payment and clients retry after timeouts. Design an idempotency mechanism that avoids both duplicate charges and falsely treating different requests as the same operation." }, { "role": "assistant", "content": "<|reason|>A stable client key identifi...
[ { "role": "user", "content": "Design a password-reset flow resistant to enumeration, token theft, replay, and log leakage. State what is stored server-side and when a token is consumed." }, { "role": "assistant", "content": "<|reason|>Use a high-entropy single-use bearer token delivered out of b...
[ { "role": "user", "content": "Explain consistent hashing for distributing keys across N cache nodes, including virtual nodes, replica selection, and how much data moves when one node is added." }, { "role": "assistant", "content": "<|reason|>A ring maps both nodes and keys into one ordered hash ...
[ { "role": "user", "content": "Describe a circuit breaker for a service dependency. Include states, concurrent probes, and how timeouts relate to retries." }, { "role": "assistant", "content": "<|reason|>The breaker limits repeated calls to a failing dependency: closed permits traffic, open rejec...
[ { "role": "user", "content": "A team wants at-most-once job execution by setting a database flag before running a job. Explain the crash window and propose a robust job-processing design." }, { "role": "assistant", "content": "<|reason|>Mark-before-work avoids duplicate starts but loses work if ...
[ { "role": "user", "content": "A multiset of n items is shuffled uniformly. Derive the probability of at least one collision when n items are independently assigned to m equally likely bins, and give a useful approximation regime." }, { "role": "assistant", "content": "<|reason|>The complement ev...
[ { "role": "user", "content": "Count derangements of n objects, prove the inclusion-exclusion formula, and provide a recurrence useful for exact computation." }, { "role": "assistant", "content": "<|reason|>Let A_i be permutations fixing position i. Inclusion-exclusion over chosen fixed positions...
[ { "role": "user", "content": "Prove Cayley’s formula that the number of labeled trees on n vertices is n^(n−2), and explain the n=1 boundary case." }, { "role": "assistant", "content": "<|reason|>A Prüfer code bijects labeled trees on n vertices with sequences of length n−2 over the same label s...
[ { "role": "user", "content": "Find the expected number of draws to see every one of n equally likely coupon types, and derive the variance." }, { "role": "assistant", "content": "<|reason|>When k types have been seen, each draw finds a new type with probability `(n-k)/n`, so the waiting time for...
[ { "role": "user", "content": "In n independent uniform assignments to m labeled boxes, derive the probability that exactly r boxes are empty. Include feasibility conditions and a normalization check." }, { "role": "assistant", "content": "<|reason|>Choose which r boxes are empty, then count surj...
[ { "role": "user", "content": "Combine congruences x≡a (mod m) and x≡b (mod n) even when moduli are not coprime. State the exact solvability condition and construct one solution." }, { "role": "assistant", "content": "<|reason|>The residues must agree modulo the gcd. After dividing by g=gcd(m,n),...
[ { "role": "user", "content": "Solve ax+by=c over integers and characterize all solutions, including zero coefficients. Explain the role of gcd and extended Euclid." }, { "role": "assistant", "content": "<|reason|>Integer combinations of a and b are exactly the multiples of g=gcd(a,b). Extended E...
[ { "role": "user", "content": "For a finite absorbing Markov chain, compute the expected number of steps to absorption from each transient state. State the condition for the linear system to be valid." }, { "role": "assistant", "content": "<|reason|>The first-step equation is `t=1+Qt`, because on...
[ { "role": "user", "content": "A diagnostic has prevalence p, sensitivity s, and specificity c. Derive the probability a positive result is a true positive and show why high accuracy alone can mislead." }, { "role": "assistant", "content": "<|reason|>Bayes’ rule compares true positives `p*s` with...
[ { "role": "user", "content": "For independent Bernoulli variables with total mean mu, state and interpret a Chernoff upper-tail bound for exceeding `(1+delta)mu`, delta>0. Give the assumptions and a simpler looser form." }, { "role": "assistant", "content": "<|reason|>Exponential Markov inequali...
[ { "role": "user", "content": "Use Jensen’s inequality to bound the average of a convex function, and characterize equality when the function is strictly convex. Explain how it can prove an extremum under a fixed-sum constraint." }, { "role": "assistant", "content": "<|reason|>Convexity places ea...
[ { "role": "user", "content": "How many binary strings of length n are distinct up to cyclic rotation (necklaces), with reflections not identified? Derive the formula using Burnside’s lemma." }, { "role": "assistant", "content": "<|reason|>Burnside averages the number of strings fixed by each rot...
[ { "role": "user", "content": "Design and implement an offline algorithm for dynamic connectivity in an undirected graph. The input is n and a sequence of operations add(u,v), remove(u,v), and connected(u,v); an edge may be added again after it has been removed, but duplicate active copies are forbidden, and...
[ { "role": "user", "content": "We need a reliable event-driven service. An API request changes our database and must eventually publish an event to a broker; consumers update their own databases. Network failures can happen at any point. Explain a design that avoids lost events and duplicate business effects...
[ { "role": "user", "content": "For a flow network with integer costs that may be negative but has no negative-cost cycle reachable in the usable residual network, describe successive shortest augmenting path with potentials. Explain why raw Dijkstra is not initially valid." }, { "role": "assistant", ...
[ { "role": "user", "content": "Reduce a 2-SAT formula to graph reachability, test satisfiability, and explain what information SCCs provide. A clause has at most two literals." }, { "role": "assistant", "content": "<|reason|>Each clause `(a OR b)` is equivalent to implications `not a -> b` and `n...
[ { "role": "user", "content": "For a finite absorbing Markov chain, compute the expected number of steps to absorption from each transient state. State the condition for the linear system to be valid." }, { "role": "assistant", "content": "<|reason|>The first-step equation is `t=1+Qt`, because on...

No dataset card yet

Downloads last month
75