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 results1,800 problems
TitleLevelTopicsSolvedTime limitMemory limitJudge
Finding a Sequence from a Sign MatrixGiven the sign pattern of all subarray sums of a hidden integer sequence, reconstruct one integer sequence (values -10 to 10) that produces the same sign matrix.Medium6Prefix sumMath+2No attempts yet2s128 MBJudgeable
SoldiersMaintain unit sizes under point updates and answer queries for which unit contains a given soldier serial number using prefix sums.Medium6Segment treeBinary search+2No attempts yet1s256 MBJudgeable
Picking Trash in the Same Increasing OrderFind the longest common strictly increasing subsequence of trash sizes recorded on two different days.Medium6Dynamic programmingArray+1No attempts yet2s128 MBJudgeable
UndoSimulate a text editor whose undo command reverts every command from the previous t seconds, where undos themselves can be undone, and find the final text.Medium6StackSimulation+2No attempts yet2s128 MBJudgeable
Parliamentary ElectionGiven vote counts for N candidates, find the minimum number of voters candidate 1 must bribe so her total strictly exceeds every other candidate's total.Medium6GreedyArray+1No attempts yet2s128 MBJudgeable
Character TrainingGiven character counts and power values per level, decide how to spend at most D training days across characters to maximize total power.Medium6Dynamic programmingGreedy+1No attempts yet2s128 MBJudgeable
Card PlacementAssign N cards with numbers and letters to N ordered bins under a numeric constraint to build the lexicographically smallest string, or report impossibility.Medium6GreedySorting+2No attempts yet2s128 MBJudgeable
Smallest RectangleFind the minimum area axis-aligned rectangle with integer coordinates whose strict interior contains at least half of N given points.Medium6GeometryBrute force+2No attempts yet2s128 MBJudgeable
Artist Lee DonghoGiven a black/white grid and a limit on horizontal single-color brush strokes, find the minimum number of cells that end up unpainted or wrongly colored.Medium6Dynamic programmingPrefix sum+2No attempts yet2s128 MBJudgeable
Morning Three and Evening FourGiven N banana weights, choose non-overlapping length-K blocks to move as a C-second group, minimizing total time and then the number of groups used, with output of chosen block positions.Medium6Dynamic programmingPrefix sum+2No attempts yet2s128 MBJudgeable
Largest Zero SubmatrixGiven a binary matrix, find the maximum area rectangle of consecutive rows and columns that contains only zeros.Medium6StackDynamic programming+2No attempts yet2s128 MBJudgeable
HistogramGiven bar heights of a histogram, find the maximum-area rectangle that fits inside it using a stack-based approach.Medium6StackArray+1No attempts yet0.7s128 MBJudgeable
Making CouplesGiven lists of men's and women's personality values, form min(n, m) man-woman couples that minimize the total absolute difference of matched values.Medium6Dynamic programmingSorting+2No attempts yet2s128 MBJudgeable
Maximum Submatrix SumGiven an N by M integer matrix, find the maximum possible sum over all contiguous rectangular submatrices.Medium6Dynamic programmingMatrix+2No attempts yet2s128 MBJudgeable
Card BundlesGiven a shuffled permutation of 1 to N, output N-1 adjacent merges that combine bundles into a single bundle where each intermediate bundle holds consecutive integers.Medium6StackGreedy+2No attempts yet2s128 MBJudgeable
Permutation RestorationGiven the inversion sequence of a permutation of 1..N, reconstruct the original permutation using an efficient data structure.Medium6Segment treeBinary search+2No attempts yet0.55s128 MBJudgeable
Adjacent MastermindGiven pairs of target and guess letter strings, compute black, grey, and white Mastermind scores by matching exact, then adjacent, then distant letters in priority order.Medium6StringGreedy+2No attempts yet1s128 MBJudgeable
HarvestFind the maximum weighted profit from repeatedly harvesting a plant from either end of a row, where each harvest's value is multiplied by its pick order.Medium6Dynamic programmingArray+1No attempts yet1s128 MBJudgeable
Bubble SortGiven an array, find the value of loop counter i when an early-exit bubble sort finishes sorting it.Medium6SortingArray+2No attempts yet2s128 MBJudgeable
Array RotationGiven a target permutation of ±1..N reachable by repeated reverse-and-negate interval operations starting from the sorted array, output a sequence of such operations that produces it.Medium6SimulationGreedy+1No attempts yet10s128 MBJudgeable
Ball ReplacementSimulate a 4-slot cache using an eviction strategy (like Belady's algorithm) that minimizes total insertions and replacements while processing a sequence of digit cards.Medium6GreedySimulation+1No attempts yet2s128 MBJudgeable
Choosing a Subarray 2Find a contiguous subarray maximizing (sum of elements) times (minimum element), and output that maximum score with the interval bounds.Medium6StackPrefix sum+1No attempts yet2s128 MBJudgeable
RaceGiven n checkpoints with scores that must be visited in increasing index order from and back to the origin, find the maximum score achievable within a runner's distance budget, for multiple runners.Medium6Dynamic programmingGeometry+1No attempts yet1s128 MBJudgeable
Box PackingSimulate dropping same-width plates into a box using column-wise collision like Tetris, opening a new box when the drop would exceed the height limit, and report each box's final height.Medium6SimulationArray+1No attempts yet2s128 MBJudgeable
Submatrix Range QueriesGiven an N x N matrix and K fixed-size BxB submatrix queries, output the max minus min value for each queried window efficiently.Medium6Sliding windowMatrix+1No attempts yet2s128 MBJudgeable
Rectangles for Four FriendsGiven up to 500,000 distinct points, count axis-aligned rectangles with fixed side lengths A and B whose corners are all present in the point set.Medium6Hash mapTwo pointers+1No attempts yet2s128 MBJudgeable
Choosing Points 2Given up to 100 points and a fixed rectangle width A and height B, find the placement that covers the maximum number of points, including boundary points.Medium6ArraySorting+1No attempts yet2s128 MBJudgeable
Divide IntervalsSelect exactly M non overlapping, non adjacent intervals from an array of up to 100 integers to maximize the total sum.Medium6Dynamic programmingArrayNo attempts yet2s128 MBJudgeable
MinesGiven N mines in a line with chain-reaction explosion rules based on impact strength, find the minimum set of mines to directly detonate so all mines explode.Medium6GreedySimulation+1No attempts yet2s128 MBJudgeable
Dumbbell SortingFind the minimum total cost of swaps (cost = sum of the two swapped weights) needed to sort an array of distinct weights into increasing order.Medium6GreedySorting+1No attempts yet2s128 MBJudgeable
Mine RemovalGiven a grid with buildings, walls, and empty cells, choose bomb placements of a fixed blast radius so every empty cell is blasted without any blast touching a building.Medium6SimulationGreedy+1No attempts yet2s128 MBJudgeable
Making Numbers EqualGiven a line of n numbers, compute the minimum number of block-increment operations (merging equal adjacent runs) needed to make all elements equal.Medium6Dynamic programmingArray+1No attempts yet2s128 MBJudgeable
Block StackingGiven max-per-row and max-per-column height arrays for a grid, determine feasibility and compute the minimum and maximum total block counts consistent with both views.Medium6GreedyMath+1No attempts yet2s128 MBJudgeable
Similar PermutationGiven a permutation, construct the lexicographically smallest permutation where each position differs from the original by at most 1.Medium6GreedyArray+1No attempts yet1s128 MBJudgeable
Sua's Candy BasketsGiven baskets on a line each decaying one candy per time unit, find the maximum total candy collectible starting from position 0 with optimal movement order.Medium6Dynamic programmingGreedy+1No attempts yet1s512 MBJudgeable
BulbsGiven N colored bulbs where changing one bulb also flips its contiguous same-colored neighbors, find the minimum number of changes to make all bulbs one color (classic zuma-like merging interval DP).Medium6Dynamic programmingArrayNo attempts yet1s128 MBJudgeable
Arranging ShapesGiven a sequence of three shape types, compute the minimum swaps needed to group each type into one contiguous block, in any order of blocks.Medium6Sliding windowGreedy+1No attempts yet1s128 MBJudgeable
LockGiven the final arrangement after a left shift, a reversal of a subrange, and another left shift, recover valid parameters k, p, q, k that reproduce it.Medium6ArraySimulation+1No attempts yet1s128 MBJudgeable
Two ReversalsGiven a permutation of 1..N produced by two interval reversals of the sorted sequence, find two reversal operations that restore sorted order.Medium6ArrayTwo pointers+1No attempts yet1s128 MBJudgeable
Rescuing the PrincessCount round trips from Yusi Island to Hooper Island and back on a line, using each island's directional-strength springboard at most once except the start, modulo 1000.Medium6Dynamic programmingArray+1No attempts yet1s128 MBJudgeable
Switches and BulbsGiven two orderings of numbers 1..N, find the longest set of wires that pairwise don't cross, which reduces to longest increasing subsequence with reconstruction.Medium6Dynamic programmingBinary search+1No attempts yet1s128 MBJudgeable
Three ReversalsGiven an array formed by reversing three intervals of 1..N, find three interval reversals (with trivial ones allowed) that restore it to sorted order.Medium6ArraySimulation+1No attempts yet1s128 MBJudgeable
Electric Wires 2Given N wires between two poles, remove the minimum number of wires so the rest form an increasing sequence (longest increasing subsequence based removal), listing the removed A-positions.Medium6Binary searchSorting+1No attempts yet1s128 MBJudgeable
IcebergSimulate yearly melting of an iceberg grid based on adjacent sea cells and find the first year it splits into multiple connected components, or 0 if it fully melts first.Medium6SimulationBFS+1No attempts yet1s256 MBJudgeable
Small LocomotivesChoose three disjoint consecutive-car segments (each up to a fixed length) from a train to maximize total passengers carried.Medium6Dynamic programmingPrefix sum+1No attempts yet1s128 MBJudgeable
Pizza SalesGiven two circular arrays of pizza-slice sizes, count ways to pick a contiguous arc from one pizza, from the other, or one arc from each, summing exactly to K.Medium6Prefix sumHash map+1No attempts yet2s128 MBJudgeable
Total Area of Several RectanglesGiven up to 30 axis-aligned rectangles, compute the total area of their union.Medium6GeometrySorting+1No attempts yet1s128 MBJudgeable
Making a Good ArrayCount pairs of indices to remove from an array so that the remaining elements have one value equal to the sum of the rest.Medium6ArrayHash map+1No attempts yet1s512 MBJudgeable
Region FillingTrace region boundaries from direction strings, validate them for out-of-bounds moves, closure, and overlaps, then flood-fill each closed boundary with its letter.Medium6SimulationImplementation+1No attempts yet1s128 MBJudgeable
Cipher Decoder Choi JunminFind the earliest starting word position in an encoded word sequence that matches a pattern sentence under a bijective word-to-word substitution mapping.Medium6String matchingHash map+1No attempts yet1s128 MBJudgeable
Lucky WheelReconstruct the letters on a rotating wheel of N distinct-letter slots from a sequence of spin distances and resulting letters, or report impossibility.Medium6SimulationArray+1No attempts yet1s128 MBJudgeable
Sum of Sequence ValuesGiven an array, compute the sum over all contiguous subarrays of (max - min) efficiently for up to 300,000 elements.Medium6StackArray+1No attempts yet1s128 MBJudgeable
Pretty IndentationGiven current and target tab counts per line, find the minimum number of range increment/decrement operations to transform one array into the other, with the constraint that decrements can't push a value below zero.Medium6GreedyArray+1No attempts yet1s128 MBJudgeable
ProgramSimulate marking multiples of several jump values into an array using a difference/counting trick, then answer many range-sum queries with prefix sums.Medium6Prefix sumArray+1No attempts yet2s256 MBJudgeable
Snow White and the DwarfsGiven a sequence of hat colors and range queries, determine for each range whether a majority color exists and identify it.Medium6Binary searchPrefix sum+1No attempts yet1s256 MBJudgeable
RabbitsGiven a range update per day using sqrt-decomposition blocks with per-block cup counters and per-rabbit matchbox counters, report the sum of newly incremented counters each day.Medium6Sliding windowImplementation+2No attempts yet2s128 MBJudgeable
Number CircleGiven a circular array of sums of each element and its two neighbors, reconstruct one valid original positive-integer circular array.Medium6MathSimulation+1No attempts yet1s128 MBJudgeable
Oasis ReunionGiven a line of heights, count pairs who can mutually see each other using a monotonic stack while handling equal-height ties correctly.Medium6StackArrayNo attempts yet1s256 MBJudgeable
New Array GameSupport left and right rotations on subarray ranges plus point queries on an array of up to 100,000 elements with up to 100,000 operations.Medium6Segment treeArray+1No attempts yet2s128 MBJudgeable
Number of PlusesCount all plus-shaped patterns of odd size at least 3 in an N x N binary matrix, where every cell outside the cross must be 0.Medium6Dynamic programmingMatrix+1No attempts yet1s128 MBJudgeable
MagnetsGiven N unit magnets that auto-merge based on adjacent poles, find the minimum number of flips needed to create a merged magnet of exact length L.Medium6GreedySimulation+1No attempts yet1s128 MBJudgeable
Grasshopper JumpsGiven a line of grasshoppers that repeatedly move by jumping left or right over B neighbors, report the maximum height jumped over for each move using an order-statistics/segment-tree-like structure over positions.Medium6Segment treeArray+1No attempts yet2s128 MBJudgeable
Turbo ModeSimulate a TV remote where number keys change channels and repeated T presses cycle through a deduplicated history segment since the current channel's last appearance.Medium6SimulationImplementation+1No attempts yet1s128 MBJudgeable
Restoring Sequence A from Sequence BReconstruct the lexicographically smallest permutation A of 1..N consistent with given prefix-set markers B and fixed positions, or report impossibility.Medium6GreedyImplementation+1No attempts yet1s128 MBJudgeable
ShelvesGiven required shelf positions in a grid, choose one ladder placement height per column to minimize the total summed climbing height covering each object from its column or adjacent columns.Medium6Dynamic programmingGreedy+1No attempts yet1s128 MBJudgeable
Arranging CardsGiven C≤4 colors with N cards each in a hand sequence, find the minimum number of single-card moves to reach some arrangement where colors form contiguous ascending-value blocks in any color order.Medium6Dynamic programmingCombinatorics+1No attempts yet1s128 MBJudgeable
Turning Off the LampsGiven lamp positions and power rates on a line and a starting point, find the walking order that minimizes total energy spent before all lamps are switched off.Medium6Dynamic programmingGreedy+1No attempts yet1s128 MBJudgeable
CandiesGiven N bags of candies, choose which bag's count to replace with a new positive value so the number of distinct subset sums is maximized, breaking ties by smallest P then smallest Q.Medium6Dynamic programmingBrute force+1No attempts yet1s128 MBJudgeable
Defense LineGiven an array, find the maximum length of a strictly increasing run achievable after deleting a single contiguous segment (possibly empty).Medium6ArrayTwo pointers+1No attempts yet3s128 MBJudgeable
Copying BooksSplit a sequence of book page counts into k contiguous groups minimizing the maximum group sum, breaking ties by minimizing earlier scribes' loads first.Medium6Binary searchGreedy+1No attempts yet1s128 MBJudgeable
Kim KangsanGiven fixed first and last pile heights, find the minimum total bricks added or removed to any middle pile so adjacent height differences stay within d.Medium6Dynamic programmingArray+1No attempts yet3s128 MBJudgeable
ShuffleGiven a song-play log and playlist size s, count starting offsets that split the log into blocks of length s (first/last possibly shorter) with no repeated song inside any block.Medium6Sliding windowArray+1No attempts yet1s128 MBJudgeable
Reseller's EyeGiven a budget and multiple sellers each offering a fixed bundle of items (buy all or none), choose a subset of sellers within budget to maximize resale profit, a bundled knapsack problem.Medium6Dynamic programmingGreedy+1No attempts yet2s128 MBJudgeable
Cubist ArtworkGiven front and side view maximum heights for a grid of cube piles, find the minimum total number of cubes consistent with both views.Medium6GreedyMatrix+1No attempts yet1s128 MBJudgeable
Make a SequenceSimulate a 3D tic-tac-toe game with gravity-dropped balls and report the first move that completes an m-in-a-row across 13 directions, or a draw.Medium6SimulationImplementation+1No attempts yet1s128 MBJudgeable
Suffix Array Re-constructionReconstruct a base string from partial suffix descriptions, where each suffix may contain one wildcard block, and decide when that is impossible.Medium6StringImplementation+2No attempts yet3s128 MBJudgeable
Polar BearSimulate Conway's Game of Life on concentric rings with special opposite-cell neighbors, then report the live count and lexicographic first and last live cells after g steps.Medium6SimulationArray+1No attempts yet5s128 MBJudgeable
The Ninja WayGiven trees in fixed left-to-right order with distinct heights, place them on integer positions so each jump to the next taller tree spans at most D, maximizing the span from shortest to tallest.Medium6Dynamic programmingArrayNo attempts yet1s128 MBJudgeable
WiFiGiven house positions on a line and a budget of n access points, place them to minimize the maximum distance from any house to its nearest access point.Medium6Binary searchGreedy+2No attempts yet1s128 MBJudgeable
Train SortingCars arrive in a fixed order; each can be attached to the front, the back, or skipped, keeping weights strictly decreasing front to back. Find the longest train.Medium6Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
BalanceGiven the polygon outline of a boat's side view, compute the centroid above and below the waterline and report whether the Center of Effort is forward, aft, or balanced, with the difference rounded to two decimals.Medium6GeometryMath+2No attempts yet1s128 MBJudgeable
Security CompanyPoints lie on a line with travel times between neighbors; starting from point a and visiting every point, minimize the total first-arrival time over all points.Medium6Dynamic programmingGreedy+2No attempts yet2s128 MBJudgeable
Pushing BoxesSimulate pushes of the four walls on unit boxes, stopping each wall when boxes are packed against the opposite wall, and report final positions sorted top-to-bottom, left-to-right.Medium6SimulationImplementation+2No attempts yet1s128 MBJudgeable
The Trip (2007)Given n bag sizes where a strictly smaller bag fits inside a larger one, find the minimum number of outermost pieces and then the smallest possible size of the largest nested piece.Medium6GreedySorting+2No attempts yet1s128 MBJudgeable
Ultra-QuickSortGiven a sequence of distinct integers, count the minimum number of adjacent swaps needed to sort it, which is the number of inversions.Medium6Divide and conquerSorting+2No attempts yet1s256 MBJudgeable
Adventures in Moving - Part IVGiven a route with up to 100 gas stations, each with a price per litre, find the cheapest way to fuel a truck with a 200-litre tank that starts and ends half full.Medium6GreedyDynamic programming+2No attempts yet1s128 MBJudgeable
The Brick Stops HereGiven N brick types with copper content and price, answer C queries: pick exactly M distinct types whose copper sum lies in [M*Cmin, M*Cmax] at minimum total price.Medium6Dynamic programmingSorting+2No attempts yet1s128 MBJudgeable
Falling LeavesGiven the leaf-removal stages of a binary search tree, reconstruct the unique tree and print its preorder traversal.Medium6TreeRecursion+2No attempts yet1s128 MBJudgeable
Roller CoasterChoose open or closed eyes for each roller coaster section to maximize total fun while keeping dizziness within limit L, where closing decreases dizziness by K.Medium6Dynamic programmingGreedy+2No attempts yet2s128 MBJudgeable
Iterated DifferenceFor each list, repeatedly replace every entry by the absolute difference with its cyclic successor and count iterations until all entries match, or report failure after 1000 steps.Medium6SimulationImplementation+2No attempts yet1s128 MBJudgeable
Contour TracingTrace each 8-connected object's boundary with the Moore tracking algorithm and print the contour length, ignoring objects smaller than 5 pixels.Medium6SimulationImplementation+2No attempts yet1s128 MBJudgeable
Vacation RentalsGiven a table of which units are free on each day, schedule a new guest's stay over [a,d) using the fewest unit changes, breaking ties by smallest unit label each night.Medium6Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
Think I'll Buy Me a Football TeamGiven a matrix of inter-bank debts, compute the total cash needed to settle all debts and the minimum possible after netting and rerouting payments.Medium6ArrayGraph+2No attempts yet1s128 MBJudgeable
Bread SortingDecide whether one permutation of 1..n can be turned into another using only the operation that rotates any three adjacent elements right by one.Medium6ArrayGreedy+2No attempts yet1s128 MBJudgeable
DoormanGiven a queue of men and women and a limit X, repeatedly admit the front or second person so the running gender difference never exceeds X, and maximize the number admitted.Medium6Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
Complaint SortGiven a sequence of n values, count the strictly decreasing subsequence triples (i < j < k with a_i > a_j > a_k).Medium6ArrayCombinatorics+2No attempts yet1s256 MBJudgeable
Computer ScienceScore each page for a query word using occurrences in the page and in linking pages weighted by word distance to the hyperlink, then print the highest scoring pages.Medium6ImplementationString+2No attempts yet1s128 MBJudgeable
Volleyball ScoresGiven a sequence of ball touches, ground hits, and out of bounds calls, compute the volleyball score while checking that the correct team serves each volley.Medium6SimulationImplementation+1No attempts yet1s128 MBJudgeable
CubingSimulate a sequence of Rubik's cube face turns from a solved state and print the colors on the up face.Medium6ImplementationSimulation+2No attempts yet1s128 MBJudgeable
Buying NotebooksEach store has a fixed shipping fee, a per-notebook price, and limited stock; buy exactly N notebooks across stores at minimum total cost.Medium6Dynamic programmingSorting+2No attempts yet1s128 MBJudgeable