Problems

Pick a problem and write your solution in the built-in editor. The judge runs it against real test cases while you watch, and the wider archive is open to read whenever you like.

Total results3,704 problems
TitleLevelTopicsSolvedTime limitMemory limitJudge
Largest RectangleGiven a binary matrix where columns may be freely reordered, find the maximum area rectangle of all-1 cells after computing per-cell run heights and sorting rows to combine widths.Medium7Dynamic programmingGreedy+2No attempts yet0.6s128 MBJudgeable
Royal TreasuryGiven a tree hierarchy, find the maximum matching between parent-child pairs and count the number of maximum matchings, likely modulo something implicit.Medium7TreeDynamic programming+1No attempts yet1s128 MBJudgeable
Bus TripFind a bus route plan from town 1 to town P arriving by time T that guarantees valid connections while minimizing worst-case total waiting time.Medium7Shortest pathGraph+1No attempts yet1s128 MBJudgeable
Character EquationGiven a recursive definition of a huge string T through variable concatenation equations, determine whether a pattern P is a subsequence of T without expanding T explicitly.Medium7Dynamic programmingString+2No attempts yet1s256 MBJudgeable
Binary Stirling NumbersGiven n and m up to 1e9, determine the parity of the Stirling number of the second kind S(n, m) for many test cases efficiently.Medium7Bit manipulationMath+2No attempts yet1s128 MBJudgeable
I-KeyboardPartition an ordered list of letter frequencies into K consecutive groups to minimize sum of frequency times in-group position, with a tie-break favoring later keys getting more letters, then output the resulting keyboard layout.Medium7Dynamic programmingGreedy+1No attempts yet1s128 MBJudgeable
CaptionGiven a fixed current pixel grid layout and a new text with letter width k and spacing bounds smin/smax, find the layout minimizing flipped pixels using DP over positions and letters with precomputed per-letter overlap costs.Medium7Dynamic programmingString+1No attempts yet1s128 MBJudgeable
Kids Like CakesGiven a convex polygon, find the triangulation using only its vertices that maximizes the area difference between the largest and smallest triangle.Medium7Dynamic programmingGeometry+1No attempts yet5s256 MBJudgeable
Kitchen RobotFind the shortest robot route that starts at a given point, visits n bottles, and drops each bottle off at the nearest border point, requiring TSP-style optimization with precomputed border distances.Medium7Dynamic programmingGeometry+1No attempts yet3s256 MBJudgeable
Auxiliary Question of the UniverseGiven a fragment of an arithmetic expression grammar (numbers, plus, parentheses), find the minimum insertions needed to make it a valid expression while keeping the fragment as a subsequence.Medium7Dynamic programmingString+1No attempts yet1s128 MBJudgeable
AntsFind the minimum-cost perfect matching between n points and n points using squared Euclidean distance as edge weight.Medium7GraphMath+1No attempts yet3s128 MBJudgeable
DFAGiven a finite set of words, compute the minimum number of states of a DFA recognizing exactly that language.Medium7TrieDynamic programming+1No attempts yet1s128 MBJudgeable
DecipheringCount the ways to split an unspaced text into dictionary words, group them into sentences, and match each sentence to a valid part-of-speech rule, capping the huge counts.Medium7Dynamic programmingString+2No attempts yet2s64 MBJudgeable
Castle GuardsGiven a recursively described tree of small buildings connected by corridors, compute the minimum vertex cover (guard placement) that watches every corridor in the whole castle.Medium7Dynamic programmingTree+2No attempts yet2s128 MBJudgeable
Mountain RoadSchedule two queues of cars crossing a one-lane road with direction-blocking and same-direction spacing rules to minimize the last car's exit time.Medium7Dynamic programmingGreedy+1No attempts yet2s128 MBJudgeable
MobileGiven a recursively nested mobile of weighted objects, find the minimum number of object weights to change so every rod balances left and right.Medium7TreeDynamic programming+1No attempts yet1s128 MBJudgeable
AmbiguousSplit a scrambled, space-free string into a unique sequence of dictionary words matching letter multisets, first and last letters, reporting ambiguity or impossibility.Medium7Dynamic programmingString+2No attempts yet1s128 MBJudgeable
Unequalled ConsumptionGiven up to 5 candy weights, find for each query P the smallest total weight whose number of representations (as an unordered multiset count) is at least P, using binary search over weight combined with counting compositions via generating functions or DP.Medium7Dynamic programmingBinary search+2No attempts yet1s128 MBJudgeable
Multiprocessor SchedulingGiven two sequences of N processor-bound procedures each, find the minimum makespan when a shared processor forces ordering constraints between the two applications.Medium7Dynamic programmingGreedy+1No attempts yet3s128 MBJudgeable
AlibabaGiven points on a line with deadlines, find the minimum finishing time to visit all points starting from an optimally chosen point, respecting each point's deadline, or report impossibility.Medium7Dynamic programmingGreedy+1No attempts yet1s128 MBJudgeable
Beautiful LayoutGiven word lengths and page width W, determine how to break the words into justified rows so that the maximum consecutive blank run is minimized, and output that minimum value.Medium7Binary searchGreedy+1No attempts yet5s128 MBJudgeable
DartsCompute win probabilities up to score 501 for two darts players with different throw distributions, where B optimizes target section each turn.Medium7Dynamic programmingProbability+2No attempts yet1s128 MBJudgeable
Power CalculusFind the minimum number of multiplications and divisions (using addition chains with subtraction allowed, keeping intermediate exponents positive) needed to build x^n for n up to 1000.Medium7Dynamic programmingMath+1No attempts yet1s128 MBJudgeable
The Best Name for Your BabyGiven a context-free grammar-like rewriting rule set, find the lexicographically smallest terminal string of exactly length l derivable from start symbol S.Medium7Dynamic programmingString+2No attempts yet1s128 MBJudgeable
Concert Hall SchedulingGiven up to 1000 interval requests with prices for two identical rooms over 365 days, select accepted intervals (assignable to either of 2 rooms without overlap) to maximize total revenue.Medium7Dynamic programmingGreedy+1No attempts yet2s128 MBJudgeable
Riding Roller CoastersGiven N coasters with fun a_i-(k-1)^2*b_i per ride and fixed ride times, answer Q queries for the maximum total fun within each time budget.Medium7Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
Exact MeasurementEach box offers up to q_i masses of weight 10^k_i; find the fewest boxes to open so the chosen masses sum to exactly x.Medium7Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
MobileGiven a full binary tree of rods and toys, find the minimum number of left-right child swaps so that all toys sit at depths differing by at most 1, with deeper toys to the left.Medium7TreeGreedy+2No attempts yet1s128 MBJudgeable
Parencedence!Two players alternately parenthesize one operator of an expression, maximizing and minimizing the value, and two rounds with swapped first movers decide the winner.Medium7Game theoryDynamic programming+2No attempts yet1s128 MBJudgeable
Sofa, So GoodGiven framing and upholstering time matrices, find the minimum-cost framing assignment, then the minimum-cost upholstering assignment, and report each worker's schedule and total idle time.Medium7Dynamic programmingBit manipulation+2No attempts yet1s128 MBJudgeable
The Banzhaf Buzz-OffGiven board members with distinct weights, count for each weight how many winning coalitions make a member with that weight a critical voter.Medium7Dynamic programmingCombinatorics+2No attempts yet1s128 MBJudgeable
GPS I Love YouFind the minimum number of roads to force so that a specified simple route becomes the shortest path favored by the GPS.Medium7GraphShortest path+2No attempts yet1s128 MBJudgeable
AbbreviationsGiven ignored stopwords, an abbreviation, and a sentence, count the distinct ways to split the abbreviation into pieces matched as subsequences of the meaningful words in order.Medium7Dynamic programmingString+2No attempts yet1s128 MBJudgeable
Family FortuneChoose K nodes in a rooted tree, no one an ancestor of another, maximizing the sum of weights; print 0 if impossible.Medium7Dynamic programmingTree+1No attempts yet10s128 MBJudgeable
Moving PointsFind the least time for one chaser to intercept N moving targets in order when the chaser is faster than every target.Medium7Dynamic programmingGeometry+2No attempts yet1s128 MBJudgeable
Counting BitsCount integers in [LO, HI] whose number of halving steps under the popcount map reaches 1 in exactly X steps.Medium7Dynamic programmingBit manipulation+2No attempts yet1s128 MBJudgeable
Lawrence of ArabiaCut at most M of the N-1 gaps in a line of weighted depots to minimize the sum of products over all still-connected pairs.Medium7Dynamic programmingPrefix sum+1No attempts yet2s128 MBJudgeable
Bridges and TunnelsGiven an undirected weighted graph whose edges are marked indoor or outdoor, answer p queries, each asking for the minimum outdoor time from one building to another, breaking ties by total time.Medium7GraphShortest path+2No attempts yet1s128 MBJudgeable
The Thirty-One GameGiven a prefix of draws in the card game Thirty-One with cards 1 to 6, decide who wins from that position under perfect play with the remaining deck.Medium7Game theoryDynamic programming+2No attempts yet1s128 MBJudgeable
ShoppingGiven weighted roads and up to 10 stores, find the shortest round trip from house 0 visiting every store.Medium7GraphShortest path+2No attempts yet3s128 MBJudgeable
Shortest Flight PathGiven airports on a sphere, find the shortest route between two airports staying inside the union of radius-R circles and within each fuel leg.Medium7GraphShortest path+2No attempts yet5s128 MBJudgeable
Stacking BowlsGiven several already-sorted stacks of bowls, find the minimum number of split and merge operations to combine them into one globally sorted stack.Medium7Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
Non-monotonicityGiven a permutation of 1 to n, find the longest subsequence whose elements alternate down, up, down, starting with a decrease.Medium7Dynamic programmingArray+2No attempts yet10s128 MBJudgeable
Choosing the Final Die's Face ValuesEach test case fixes several dice and asks for the r face values of the last die so that m given sums appear with exactly the given counts, choosing the lexicographically smallest set.Medium7Dynamic programmingPrefix sum+2No attempts yet1s128 MBJudgeable
Polly NomialsFor each polynomial with leading coefficient 1, evaluate it at x = 1 or -1 and find the minimum key presses needed to compute it on a left-to-right calculator.Medium7Dynamic programmingMath+2No attempts yet1s128 MBJudgeable
Preorder and PostorderCount how many m-ary trees share the given pre-order and post-order traversals.Medium7TreeDynamic programming+2No attempts yet1s128 MBJudgeable
Cousin StringsFind the smallest n such that x is an n-th cousin of y, where each cousin step requires a common string reachable by deleting at most half of each string, or report that no n exists.Medium7GraphBFS+2No attempts yet1s128 MBJudgeable
So You Want to Be a 2ⁿ-aire?A contestant with a current prize faces n questions; each question's success chance p is uniform on [t,1]. Find the optimal expected prize, to three decimals.Medium7Dynamic programmingProbability+2No attempts yet1s128 MBJudgeable
Grid SpeedGiven a grid of streets with speed limits, find the earliest arrival time within a time window and the most fuel-efficient trip, choosing speeds per segment.Medium7GraphShortest path+2No attempts yet5s128 MBJudgeable
Tango Tango InsurrectionGiven a sequence of required taps or rests, find the minimum total energy for the two feet under per-foot cost and crossover rules.Medium7Dynamic programmingSimulation+2No attempts yet1s128 MBJudgeable
Dumb BonesGiven the chance that each placed domino tips left or right, find the minimum expected total placements needed to finish a run of n dominoes.Medium7Dynamic programmingProbability+1No attempts yet1s128 MBJudgeable
Edit Step LaddersGiven a lexicographically sorted dictionary, find the longest sequence of words where each consecutive pair differs by one insertion, deletion, or substitution, and the sequence follows dictionary order.Medium7Dynamic programmingString+2No attempts yet1s128 MBJudgeable
YahtzeeGiven 13 rounds of five dice, assign each round to a distinct Yahtzee category to maximize total score including the upper-section bonus.Medium7Dynamic programmingBit manipulation+1No attempts yet1s128 MBJudgeable
Temple BuildGiven an ideal truncated square pyramid and three brick cube sizes, stack square layers fully inside the shape to maximize total volume.Medium7Dynamic programmingMath+2No attempts yet3s128 MBJudgeable
BraceletsGiven two circular strings, find the longest common subsequence that can be read in the same or opposite orientation on the two bracelets, and report twice its length.Medium7Dynamic programmingString+2No attempts yet30s256 MBJudgeable
Crazy CircuitsGiven a directed acyclic circuit with current demands on edges, find the minimum supply current at the + terminal so every component gets its required current, or report impossible.Medium7GraphDynamic programming+2No attempts yet1s128 MBJudgeable
YO!Count paint-over patterns of a short string whose remaining letters, read left to right, form one or more dictionary words without overlap.Medium7Dynamic programmingString+2No attempts yet1s128 MBJudgeable
Shut the BoxGiven N pieces labeled 1 to N and up to T turn values, mark disjoint sets of unmarked pieces summing exactly to each turn value in order, and find the largest total number of pieces markable.Medium7Dynamic programmingBit manipulation+2No attempts yet1s128 MBJudgeable
The Law of the JungleGiven up to 20 bridges with capacity and crossing time, simulate the two rules to find the minimum total time for all people to cross.Medium7SimulationGreedy+2No attempts yet1s128 MBJudgeable
Two MountaineersGiven a polygonal mountain profile with equal endpoints, find the minimum total elevation change for two climbers who swap endpoints while staying at equal height.Medium7Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
Safety in AlchemyGiven reaction heats between pairs of chemicals and limited amounts of each chemical, find the maximum total heat that can be produced.Medium7GraphDynamic programming+2No attempts yet1s128 MBJudgeable
Enigmatic TravelFor each complete graph size L, compute the average cost of a random walk, a random simple path, and a random simple cycle.Medium7CombinatoricsMath+1No attempts yet1s128 MBJudgeable
Covered WalkwayCover all required points on a line with segments, where covering from x to y costs c plus (x - y) squared, minimizing total cost.Medium7Dynamic programmingDivide and conquer+1No attempts yet10s128 MBJudgeable
EstimationPartition an array into k contiguous sections, each replaced by one constant value, to minimize the total absolute error. Multiple test cases until 0 0.Medium7Dynamic programmingDivide and conquer+2No attempts yet5s128 MBJudgeable
Wealthy FamilyGiven a rooted tree with a weight on each node, pick exactly k nodes with no ancestor relation between any two, maximizing the total weight, over multiple test cases.Medium7TreeDynamic programming+2No attempts yet1s128 MBJudgeable
ClickomaniaGiven a string over uppercase letters, decide whether the one dimensional Clickomania puzzle can be fully cleared.Medium7Dynamic programmingIntervals+1No attempts yet10s128 MBJudgeable
Team WorkSplit the given pieces into three groups of equal total length, using each piece at most once, and report the largest such length or 0.Medium7BacktrackingBrute force+1No attempts yet5s128 MBJudgeable
String EquationsDecide whether a subset of distinct short strings and their repeats can be split into two groups whose multiset union of characters is identical.Medium7MathNumber theory+2No attempts yet1s128 MBJudgeable
Knight StoryAssign N knights to N distinct target cells on an infinite chessboard to minimize the total number of knight moves.Medium7Dynamic programmingShortest path+2No attempts yet1s128 MBJudgeable
Value of a TriangleGiven up to 400 rows of a triangular grid of unit triangles, find the sub-triangle with the largest sum of unit values.Medium7Dynamic programmingPrefix sum+2No attempts yet1s256 MBJudgeable
Let's Go to the MoviesEach family is a parent with children, and tickets are either singles or family tickets (one parent plus any subset of their own children). Find the arrangement minimizing cost, breaking ties by fewest tickets.Medium7Dynamic programmingGreedy+1No attempts yet1s128 MBJudgeable
I Hate Number TheoryFor each query interval [L, U] below one million, find the maximum of a score built from prime-factor counts over all subintervals [a, b].Medium7Number theoryPrefix sum+1No attempts yet1s128 MBJudgeable
Round TripFind a non-descending path from town 1 to town n and a non-ascending path back, sharing the first-visit visa fee of each town, minimizing total road cost plus fees.Medium7GraphShortest path+2No attempts yet1s128 MBJudgeable
And Then, How Many Are There?Given stacked discs of four colors, repeatedly remove two same-colored discs that are both uncovered; find the maximum number of discs removable.Medium7Dynamic programmingBit manipulation+2No attempts yet5s128 MBJudgeable
Pollock's conjectureFor each integer below 10^6, find the fewest tetrahedral numbers that sum to it, and the fewest odd tetrahedral numbers that do.Medium7Dynamic programmingNumber theory+2No attempts yet1s128 MBJudgeable
Discrete SpeedFind the fastest route from a start to a goal city where a car enters each road at an integer speed, changes speed by at most 1 per city, starts and ends at speed 1, and cannot U-turn.Medium7GraphShortest path+2No attempts yet8s128 MBJudgeable
CardsGiven blue and red cards with numbers, find the maximum number of blue-red pairs whose two numbers share a common divisor greater than 1.Medium7GraphNumber theory+2No attempts yet5s128 MBJudgeable
Traveling by StagecoachWith up to 8 one-use tickets, each giving a speed, find the fastest route from city a to city b, or report Impossible.Medium7GraphShortest path+2No attempts yet3s128 MBJudgeable
Robot VacuumFind the minimum number of moves for a robot to visit and clean all dirty cells in a grid with furniture, or report -1 if some are unreachable.Medium7BFSShortest path+2No attempts yet1s256 MBJudgeable
Power BloggerFind the cheapest closed walk from city 1 that traverses every required edge at least once, using optional extra edges.Medium7GraphDynamic programming+2No attempts yet1s128 MBJudgeable
Allergy TestFind the shortest non-adaptive schedule for applying allergens on a single morning each day so that every reaction pattern identifies exactly the allergy set.Medium7CombinatoricsBit manipulation+2No attempts yet1s128 MBJudgeable
Code TheftNormalize two sets of source lines and find the longest consecutive run of lines common to both, reporting the length and which files achieve it.Medium7StringHash map+1No attempts yet1s128 MBJudgeable
Fixing the BugsWith B bugs, T hours, and a failure factor f, choose each hour's bug by dynamic programming to maximize the expected total severity fixed.Medium7Dynamic programmingProbabilityNo attempts yet1s128 MBJudgeable
Full Tank?For each query (tank capacity c, start s, goal e), find the minimum fuel cost to drive from s to e, buying gas only at cities at given prices; output impossible if unreachable.Medium7GraphShortest path+2No attempts yet1s128 MBJudgeable
Nested DollsGiven a set of dolls with widths and heights, partition them into the fewest strictly increasing chains in both dimensions, which equals the longest antichain by Dilworth's theorem.Medium7SortingDynamic programming+2No attempts yet1s128 MBJudgeable
Moogle MapsChoose c of h house locations to store so that the average linear interpolation error over all houses is minimized, with endpoints always stored.Medium7Dynamic programmingMath+2No attempts yet1s128 MBJudgeable
Whac-a-MoleGiven each mole's position and time, find the maximum number of moles whacked while the hammer moves at most distance d between time steps.Medium7Dynamic programmingGeometry+1No attempts yet1s128 MBJudgeable
Random WalkingFor each graph, decide whether every bit position in every one of k random walk outputs has a 1-probability strictly between 25% and 75%.Medium7GraphProbability+2No attempts yet1s128 MBJudgeable
Team DessertDesserts sit in a row; two alternating teams take from either end, and the first-picking team wants the smallest total weight it can guarantee against optimal play.Medium7Dynamic programmingGame theory+2No attempts yet1s128 MBJudgeable
Congested NetworksFor each connected graph with at most 40 nodes, find the maximum number of edge-disjoint paths between any pair of nodes.Medium7GraphUnion-find+2No attempts yet1s128 MBJudgeable
Ice CreamFind the minimum cost to buy single, double, and triple scoops from two flavors so every customer's vanilla and chocolate counts are met without contaminating one-flavor orders.Medium7GreedyDynamic programming+2No attempts yet1s128 MBJudgeable
Segment PricingChoose a non-increasing fare for each boarding stop, with riders boarding only if their budget covers it, to maximize total revenue.Medium7Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
Cherry PickingChoose one premium per category so at least m patients are insured and total premiums minus benefits is maximized.Medium7Dynamic programmingSorting+2No attempts yet1s128 MBJudgeable
The Hare and the HedgehogsHedgehogs of equal speed start at given points and may move freely; find the maximum number of legs they can collectively reach exactly when the hare arrives.Medium7GeometryDynamic programming+1No attempts yet1s128 MBJudgeable
Campaign StopsPick campaign stops and a round tour from city 1 that sways the most voters within the available hours.Medium7Dynamic programmingGraphNo attempts yet1s128 MBJudgeable
Find Fame in the Disc ArenaA DAG gives games with fame values and prerequisite sets; pick a closed-under-prerequisites set (possibly empty) maximizing total fame.Medium7GraphDynamic programming+2No attempts yet5s128 MBJudgeable
BOI-handsome NumbersCount digit strings over {1,2,3} of length n that avoid forbidden adjacent pairs, comparing them under an order given by a permutation of positions, up to a bound B.Medium7Dynamic programmingCombinatorics+2No attempts yet1s256 MBJudgeable
TrapezoidsPick the most pairwise disjoint trapezoids between two lines and count those optimal sets modulo 30013.Medium7Dynamic programmingSorting+1No attempts yet1s128 MBJudgeable
Gold Coin GameGiven S coins and a legal move set of powers of K, find the smallest first move that guarantees a win for the starting player, or 0 if none exists.Medium7Game theoryMath+1No attempts yet1s128 MBJudgeable
Top 2000Partition a fixed sequence of singles into contiguous blocks, letting each block run under or over M minutes with per-minute penalties, and minimize the total penalty.Medium7Dynamic programmingPrefix sum+2No attempts yet1s128 MBJudgeable