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
Valid ArrayGiven a distinct integer array, find the minimum number of elements to add so it contains five consecutive integers.Medium4ArrayBrute force+1No attempts yet2s128 MBJudgeable
Flammable Railway 997Given fireproof material amounts between train cars and a starting fire location, compute the time step when a target car explodes, or report it never does.Medium4Prefix sumSimulation+2No attempts yet2s128 MBJudgeable
Triangle BuilderGiven N straw lengths, pick three that form a triangle with the largest possible perimeter, or report -1 if none exist.Medium4SortingGreedy+1No attempts yet2s128 MBJudgeable
Building Rest StopsGiven existing rest stops on a highway, place M new integer-position stops to minimize the longest gap between consecutive stops, found via binary search.Medium4Binary searchGreedy+1No attempts yet2s128 MBJudgeable
Selling GoodsGiven each buyer's max price and delivery cost, choose a sale price (ties broken by lowest) that maximizes total profit summed over buyers who purchase profitably.Medium4Brute forceSorting+2No attempts yet2s128 MBJudgeable
GuitaristGiven a starting volume and a sequence of forced up/down changes bounded by [0, M], find the maximum achievable volume for the last song using reachability DP.Medium4Dynamic programmingArrayNo attempts yet2s128 MBJudgeable
Bubble Sort Swap CountCount the number of adjacent swaps bubble sort performs to sort an array, equivalent to counting inversions efficiently.Medium4SortingDivide and conquer+1No attempts yet1s512 MBJudgeable
Number of RoadsCount right/up lattice paths from (0,0) to (N,M) on a grid where certain unit edges are blocked by construction.Medium4Dynamic programmingMatrix+1No attempts yet2s16 MBJudgeable
Cable CuttingGiven K cable lengths, binary search the maximum integer cut length so that summing floor(length/cut) over all cables reaches at least N pieces.Medium4Binary searchGreedy+1No attempts yet2s128 MBJudgeable
Magic Square RotationsGiven four fixed permutations that can be applied to an 8-number arrangement, find the minimum number of operations to reach a target arrangement from the initial one via BFS.Medium4BFSSimulation+1No attempts yet2s128 MBJudgeable
Same RemainderGiven a sequence, find the largest divisor D so that all numbers leave the same remainder when divided by D.Medium4Number theoryMath+1No attempts yet2s128 MBJudgeable
Polynomial RemaindersCompute the remainder polynomial when dividing a given polynomial by x^k + 1, using the fact that x^k ≡ -1.Medium4MathArray+1No attempts yet1s128 MBJudgeable
Center of SymmetryDecide whether a set of up to 10000 integer points has a center point such that every point's mirror image is also in the set.Medium4Hash mapGeometry+2No attempts yet1s128 MBJudgeable
Partial SumFind the minimum length of a contiguous subarray whose sum is at least S, or 0 if none exists.Medium4Sliding windowTwo pointers+1No attempts yet0.5s128 MBJudgeable
CandyGiven the sums of adjacent candy counts for N students seated in an odd-sized circle, recover each student's exact candy count.Medium4MathArray+1No attempts yet2s128 MBJudgeable
Box NestingFind the length of the longest strictly increasing subsequence of box sizes given in order.Medium4Dynamic programmingBinary search+1No attempts yet2s128 MBJudgeable
Sum of Numbers 4Count the number of contiguous subarray sums of an array that equal a given target K, using prefix sums and a hash map.Medium4Prefix sumHash map+1No attempts yet2s128 MBJudgeable
Matchstick GridGiven an ASCII 3x3 matchstick grid, count how many matchsticks were removed and how many complete squares of any size remain.Medium4SimulationImplementation+1No attempts yet2s128 MBJudgeable
Range Sum Query with UpdatesSupport point updates and range-sum queries on an array of up to a million integers using a Fenwick tree or segment tree.Medium4Segment treeArray+1No attempts yet2s256 MBJudgeable
Sum of Numbers 7Support point updates and range sum queries on an array of up to 1,000,000 elements over up to 1,000,000 operations, requiring a Fenwick tree or segment tree.Medium4Segment treePrefix sum+1No attempts yet2s256 MBJudgeable
Minimum and MaximumGiven N numbers and M range queries, output the minimum and maximum value within each query's index range.Medium4Segment treeArrayNo attempts yet2s192 MBJudgeable
Maximum DistanceGiven up to 50,000 points, compute the maximum L1 (Manhattan) distance between any two of them.Medium4MathGreedy+1No attempts yet1s128 MBJudgeable
Finding Silent IntervalsFind every starting index of a length-m window in an array where the max minus min value is at most c, using a sliding window with monotonic deques.Medium4Sliding windowQueue+1No attempts yet1s128 MBJudgeable
Smallest Unmeasurable WeightGiven N integer weights usable only on one pan, find the smallest positive integer amount that cannot be formed as a subset sum.Medium4GreedySorting+1No attempts yet1s128 MBJudgeable
Two Liquids Closest to ZeroGiven a sorted array, find two distinct numbers whose sum is closest to zero using a two-pointer sweep.Medium4Two pointersArray+1No attempts yet1s128 MBJudgeable
Two LiquidsGiven N distinct integers, sort them and use two pointers to find the pair whose sum is closest to zero.Medium4Two pointersSorting+1No attempts yet1s128 MBJudgeable
Shuffle SequenceGiven a permutation of size N, compute the least common multiple of its cycle lengths, which is the number of shuffles needed to restore the original order.Medium4MathArray+1No attempts yet1s128 MBJudgeable
TowersFor each tower in a line, find the nearest tower to its left with height at least as large, using a monotonic stack approach.Medium4StackArrayNo attempts yet1.5s128 MBJudgeable
Finding RegionsGiven a grid with several rectangles marked as blocked, find the number of connected empty regions and output their areas sorted ascending.Medium4BFSArray+1No attempts yet1s128 MBJudgeable
Fire EnginesGiven sorted positions of pumps and fire engines on a line, assign each engine a distinct pump to minimize total distance connected.Medium4GreedyDynamic programming+1No attempts yet1s128 MBJudgeable
Selecting NumbersGiven a functional graph i->A_i on 1..N, find the maximum set of indices closed under this mapping (union of cycles) and print it.Medium4GraphArray+1No attempts yet1s128 MBJudgeable
Maximum Product of a Contiguous SubsequenceGiven N decimal numbers between 0.0 and 9.9, find the contiguous subsequence with the maximum product and print it rounded to three decimals.Medium4Dynamic programmingArrayNo attempts yet1s128 MBJudgeable
Pancake FlippingSort a stack of N distinct pancakes into increasing order from top using prefix reversals, within a bound of 2N-3 flips.Medium4GreedySimulation+1No attempts yet1s128 MBJudgeable
Candy Sharing GameSimulate a circle of students repeatedly halving and passing candies right, rounding odd counts up, until all counts equalize, then report the round count and final value.Medium4SimulationArrayNo attempts yet1s128 MBJudgeable
Box SortingSort an array into increasing order using the minimum number of cyclic-rotation commands, following a specified cycle-decomposition construction.Medium4ArraySimulation+1No attempts yet1s128 MBJudgeable
A Library at HomeFind the minimum number of top-moves needed so a pile of numbered books ends up sorted 1..N from top to bottom.Medium4GreedyArrayNo attempts yet1s128 MBJudgeable
Graphics QuizFor each of 5 grades, find the longest contiguous run of desks where at least one student has that grade, then output the best length and the smallest grade achieving it.Medium4ArraySliding window+1No attempts yet1s128 MBJudgeable
Seat WarGiven a grid of people and seats, count seats where two or more people are tied at the minimum distance to that seat.Medium4ArrayBrute force+1No attempts yet1s128 MBJudgeable
Next Greater Number with the Same DigitsGiven an integer, find the smallest number larger than it using exactly the same multiset of digits, or print 0 if impossible.Medium4GreedyArray+1No attempts yet1s128 MBJudgeable
Choosing a NameGiven even integers and a range [A,B], find an odd integer in that range maximizing the minimum distance to all given even values.Medium4ArrayGreedy+1No attempts yet1s128 MBJudgeable
FireflyGiven alternating stalagmite and stalactite lengths in a cave, find the flight height destroying the fewest obstacles and how many heights tie for that minimum.Medium4Prefix sumArrayNo attempts yet1s128 MBJudgeable
AntsSimulate two colliding groups of ants swapping adjacent opposite-direction ants each second and output the arrangement after T seconds.Medium4SimulationArrayNo attempts yet1s128 MBJudgeable
Bridging SignalsGiven a permutation of wire connections between two ports, find the longest increasing subsequence to maximize non-crossing signals.Medium4Binary searchDynamic programming+1No attempts yet1s128 MBJudgeable
Battle Order ScoreCount pairs of items whose relative order matches between a reference sequence and a given permutation, and print as a fraction over N(N-1)/2.Medium4ArrayBrute force+1No attempts yet1s128 MBJudgeable
Good FriendsCount pairs of students within rank distance K whose names have equal length, given names in rank order.Medium4Sliding windowArray+1No attempts yet1s128 MBJudgeable
Candy GameGiven a colored N×N grid, determine the longest same-color run achievable in any row or column after performing exactly one swap of two adjacent different-colored cells.Medium4SimulationBrute force+1No attempts yet1s128 MBJudgeable
Teams with Sum ZeroCount the number of index triples among N students whose skill values sum to exactly zero.Medium4ArrayTwo pointers+1No attempts yet4s128 MBJudgeable
Kkung the ShepherdUsing grid flood-fill to find fenced regions, determine for each region whether sheep or wolves survive by comparing counts, then output totals.Medium4BFSArray+1No attempts yet1s128 MBJudgeable
MOSimulate an alternating stone-placing game on a 1D board where placing a stone can capture an enclosed run of opponent stones, then count remaining stones of each color.Medium4SimulationArray+1No attempts yet1s128 MBJudgeable
Who Wins Gold, Silver, and Bronze?Given each athlete's live rank as they finish two sequential races, reconstruct final standings from the second race and output the top three athlete numbers.Medium4SimulationArray+1No attempts yet1s128 MBJudgeable
SpiesSimulate a walk on a grid and report which given spy coordinates ever fall within Chebyshev distance 1 of the walker's path.Medium4SimulationArrayNo attempts yet1s128 MBJudgeable
SearchTrack all reachable cells on a grid as a car moves in given directions by at least one free cell each step, then mark final possible positions.Medium4SimulationArray+1No attempts yet1s128 MBJudgeable
Multi-key SortingGiven a sequence of stable column sorts, output the shortest equivalent sequence by keeping only the last occurrence of each column value in the order that determines the final effect.Medium4ArrayGreedy+1No attempts yet2s128 MBJudgeable
The RiddleFind the minimum prefix length of a coin sequence so that all values from 1 to K are achievable as subset sums, using the classic greedy reachable-range extension, or report -1.Medium4GreedyArray+1No attempts yet1s128 MBJudgeable
Reducing a SequenceGiven a sequence, find the minimum total cost of repeatedly merging adjacent elements where cost equals the max of the pair, until one element remains.Medium4GreedyArrayNo attempts yet1s128 MBJudgeable
Robot ProjectGiven a target length and up to a million rod lengths, find two rods summing exactly to the target with the maximum length difference, or report impossibility.Medium4Two pointersSorting+1No attempts yet5s256 MBJudgeable
Movie CollectionGiven a stack of DVDs and a sequence of watched movie numbers, output for each watch how many DVDs sat above it before moving it to the top.Medium4ArraySimulation+1No attempts yet1s256 MBJudgeable
Divisible Contiguous SubarraysCount contiguous subarrays whose sum is divisible by a given d, using prefix sums modulo d and counting equal remainders.Medium4Prefix sumHash map+1No attempts yet1s128 MBJudgeable
TableGiven an N by M table, compute each column's product and output the column index (largest index on tie) with the maximum product, handling big products across up to 1000 rows.Medium4MathSimulation+1No attempts yet1s128 MBJudgeable
Rising TrendFor each test case, compute the length of the longest strictly increasing subsequence in a sequence of up to 100000 prices.Medium4Dynamic programmingBinary search+1No attempts yet1s128 MBJudgeable
Republic of KoreaCount crossing pairs among K straight highways linking numbered east and west coast cities, using inversion counting.Medium4SortingDivide and conquer+1No attempts yet1s128 MBJudgeable
TourGiven points sorted by x-coordinate, compute the shortest bitonic tour that goes strictly left-to-right then strictly right-to-left, using classic O(n^2) DP.Medium4Dynamic programmingGeometry+1No attempts yet1s128 MBJudgeable
Condorcet ParadoxGiven b ranked ballots over c candidates, find the candidate who beats every other candidate head to head on more than half the ballots.Medium4ArraySimulation+2No attempts yet5s128 MBJudgeable
CDGiven two sorted lists of distinct CD numbers, count how many numbers appear in both lists.Medium4Two pointersSorting+1No attempts yet1s256 MBJudgeable
Unique SnowflakesGiven a stream of integer snowflake ids, find the length of the longest contiguous block in which every value is distinct.Medium4Sliding windowHash map+2No attempts yet1s128 MBJudgeable
The Dragon of LoowaterMatch the smallest knight to each dragon head so that every head is cut by a tall enough knight, minimizing total height paid; report failure if impossible.Medium4GreedySorting+2No attempts yet1s128 MBJudgeable
InterpreterSimulate a 10-register, 1000-word RAM machine that executes encoded 3-digit instructions, and count how many instructions run before the halt.Medium4SimulationImplementation+2No attempts yet1s128 MBJudgeable
Australian VotingSimulate multi-round preferential voting: eliminate the lowest candidates each round and transfer their ballots until someone exceeds 50% or a tie remains.Medium4SimulationImplementation+2No attempts yet1s128 MBJudgeable
Let the Wookiee Win!On a 5x5 board, find the single empty square where playing O neither makes four O in a row nor blocks any of X's winning squares.Medium4ImplementationBrute force+2No attempts yet1s128 MBJudgeable
Wandering AimlesslySimulate NPC movement scripts on a grid, converting blocked steps into pauses, looping or reversing scripts, and print the map after T turns.Medium4SimulationImplementation+1No attempts yet1s128 MBJudgeable
Tribute (Editor)Simulate a buggy modal editor: given keystrokes, apply insert, delete, duplicate, reverse, and cursor commands, then print the buffer with a caret marking the cursor position.Medium4SimulationImplementation+2No attempts yet1s128 MBJudgeable
Artificial StrifeSimulate multiple Game of Life rule sets on one grid for T turns, resolving collisions alphabetically, and report each species' maximum and minimum population.Medium4SimulationArray+1No attempts yet1s128 MBJudgeable
JugglefestSimulate the first 20 throws of a siteswap pattern, assigning balls in order of first use, and detect any time two balls are due on the same throw.Medium4SimulationImplementation+2No attempts yet1s128 MBJudgeable
Pascal's TravelsCount paths on an n by n digit board from top-left to bottom-right, where each square's digit sets the exact right or down step length.Medium4Dynamic programmingArray+2No attempts yet1s128 MBJudgeable
ColorvilleSimulate players advancing on a colored board by drawing cards, and report who wins or that the deck ran out.Medium4SimulationImplementation+2No attempts yet1s128 MBJudgeable
Instruens FabulamRead a header specifying each column's alignment, then print each table with borders, sized columns, and aligned cells.Medium4StringImplementation+2No attempts yet1s128 MBJudgeable
MapmakerGiven array declarations with bounds and element sizes, compute each reference's physical address with the row-major address formula.Medium4ArrayMath+2No attempts yet1s128 MBJudgeable
Portfolio RebalancingSimulate each term's fixed fee, percentage fee, and return per instrument, pool and redistribute every NREBALANCE terms, and print each ending balance to two decimals.Medium4SimulationImplementation+2No attempts yet1s128 MBJudgeable
Wooden BlocksGiven a string of digit pieces, check whether it forms a valid interlocking arrangement starting with piece 1, ending with piece 2, and matching every adjacent edge pair.Medium4ImplementationString+2No attempts yet1s128 MBJudgeable
Still Johnny Can't AddDecide whether an N by N grid can be written as row label plus column label for all cells, up to N=10.Medium4ArrayMath+2No attempts yet1s128 MBJudgeable
Pablo Squarson's HeadacheGiven how N unit squares are attached one by one to an existing square in one of four directions, compute the width and height of the resulting figure.Medium4SimulationArray+2No attempts yet1s128 MBJudgeable
Exotic FoodsGiven a sequence of food values, choose a subset with no two chosen positions adjacent so the total value is as large as possible.Medium4Dynamic programmingArray+2No attempts yet1s128 MBJudgeable
EcosystemGiven populations and per-member diets for species ordered by food chain position, simulate feeding in increasing species order and report survivors.Medium4SimulationImplementation+2No attempts yet1s128 MBJudgeable
RotateReverse a sequence of operations: first undo a rotation of each block of K, then undo a rotation of the whole sequence, recovering the original array.Medium4ImplementationSimulation+1No attempts yet1s128 MBJudgeable
Shut the Box IGiven a target sum and a sorted list of open card values, choose the subset summing to the target that is lexicographically largest when sorted.Medium4BacktrackingArray+2No attempts yet1s128 MBJudgeable
Coin CollectionA robot walks right or down only from the top-left to the bottom-right of a grid, and we want the most coins it can pick up along the way.Medium4Dynamic programmingMatrix+2No attempts yet1s128 MBJudgeable
Next PermutationGiven an integer A, find the smallest permutation of its digits that is strictly greater than A, or print USELESS if none exists.Medium4ArrayString+2No attempts yet1s128 MBJudgeable
ACApply a string of reverse (R) and discard-first (D) operations to an integer array, printing the result or error if D hits an empty array.Medium4ImplementationArray+1No attempts yet1s256 MBJudgeable
Planet ExplorationGiven a grid of jungle, sea, and ice cells, answer many rectangle queries by counting how many cells of each terrain type fall inside.Medium4Prefix sumArray+2No attempts yet1s256 MBJudgeable
PizzaGiven store positions on a circular road and delivery points, sum the distance from each point to its nearest store.Medium4Binary searchArray+1No attempts yet2s128 MBJudgeable
Tornado!Given a circular fence of N posts marked standing or broken, choose the fewest broken posts to fill so no wire span between standing posts exceeds 4 meters.Medium4GreedyArray+2No attempts yet1s128 MBJudgeable
BrothersGiven a grid of counties owned by heirs in a cycle, apply K simultaneous rounds where a cell switches to the previous heir if an orthogonal neighbor already has that heir, then print the grid.Medium4SimulationImplementation+2No attempts yet1s128 MBJudgeable
Where Are My GenesApply a sequence of reversals to the identity genome and report the final position of each queried gene.Medium4SimulationArray+1No attempts yet1s128 MBJudgeable
DiceSimulate a board game where players advance by dice totals, skip a turn when landing on one of three traps, and the first past the last square wins.Medium4SimulationImplementation+1No attempts yet1s128 MBJudgeable
Cow CrossingsCount cows whose straight crossing paths intersect no other cow, where two paths cross exactly when the start and end left-to-right orders differ.Medium4SortingArray+2No attempts yet1s128 MBJudgeable
Meet and GreetSimulate two cows walking along a line at unit speed and count how many times they meet after being apart, excluding the start.Medium4SimulationImplementation+2No attempts yet1s128 MBJudgeable
iPhone 9SRemove everyone in the line who wants one chosen capacity, then report the longest run of equal capacities that remains. Choose the capacity to maximize that run.Medium4ArrayImplementation+2No attempts yet1s128 MBJudgeable
Rope FoldingGiven knots at integer positions on a rope, count the fold points where every knot in the overlapping interval mirrors onto another knot.Medium4ArrayBrute force+2No attempts yet1s128 MBJudgeable
Haybale StackingAdd one bale to every stack in each given range, then report the median height among all N stacks.Medium4Prefix sumArray+2No attempts yet1s128 MBJudgeable
Moo SickFind every window of C consecutive notes whose sorted, min-subtracted shape matches the given chord's shape.Medium4ArraySorting+2No attempts yet1s128 MBJudgeable