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
Break Walls and Move 2Find the shortest path length from the top-left to the bottom-right of an N by M grid, where you may break at most K walls along the way.Medium6BFSGraph+2No attempts yet2s512 MBJudgeable
Why Did the Cow Cross the Road 12Given the left and right orderings of N breeds along a road, count pairs whose segments cross and whose breed numbers differ by more than K.Medium6Divide and conquerSorting+2No attempts yet2s512 MBJudgeable
Why Did the Cow Cross the Road 9Given a circular sequence where each cow label appears exactly twice, count pairs of cows whose chords necessarily cross.Medium6ArrayHash map+2No attempts yet2s512 MBJudgeable
Ground DefenseHandle updates that add an arithmetic sequence of troops along a line of cities in one direction, and answer queries for a city's running total.Medium6Prefix sumImplementation+2No attempts yet2s512 MBJudgeable
After-Party Drink CapFind the smallest cap S such that each person i gets an integer amount in [L_i, min(R_i, S)] and the amounts sum exactly to T.Medium6GreedyBinary search+2No attempts yet1s128 MBJudgeable
Mission ImprobableGiven a grid of pile heights, find the maximum number of crates that can be removed while keeping every row maximum, column maximum, and empty/non-empty pattern unchanged.Medium6GreedyArray+2No attempts yet1s512 MBJudgeable
A rain of shooting starsPlace an axis-aligned square of side L to cover as many of K points as possible, counting points on any edge as covered.Medium6ArraySorting+2No attempts yet2s256 MBJudgeable
Sickly YunhoGiven a string of B, L, D doses, remove from either end in the fixed order B, L, D, B, L, D... and find the most doses removable before the required dose is missing from both ends.Medium6Dynamic programmingArray+2No attempts yet1s512 MBJudgeable
The Longest FenceGiven up to 10^6 board lengths (each at most 2000), pair them into boards of equal sum and report the largest possible number of boards plus how many sums reach it.Medium6ArrayTwo pointers+2No attempts yet2s512 MBJudgeable
Cutting the puzzleGiven the heights of a histogram, find the area of the largest axis-aligned rectangle contained in it.Medium6StackArrayNo attempts yet2s256 MBJudgeable
Impossible DesignGiven the circle order of a permutation of 0 to N-1, decide whether chords drawn between every pair at height x+y ever intersect.Medium6GeometryCombinatorics+1No attempts yet1s128 MBJudgeable
Closest PairBoth point sets lie on horizontal lines; find the Manhattan distance of the closest P-Q pair and count how many distinct pairs achieve it.Medium6SortingTwo pointers+1No attempts yet1.5s512 MBJudgeable
Dumpling shop owner Seungwon ParkMake at most limited numbers of m filler dumplings and unlimited filler-free ones from n grams of flour to maximize sales.Medium6Dynamic programmingGreedy+1No attempts yet2s512 MBJudgeable
CatsFind the minimum number of moves to reorder a line of cats, dogs, and lions so no cat is adjacent to a dog.Medium6GreedyDynamic programming+2No attempts yet1s16 MBJudgeable
Subarray XOR sumsFor a sequence, count how often each XOR value appears among all contiguous subarrays, then report the most frequent value, breaking ties by choosing the smallest.Medium6Prefix sumBit manipulation+2No attempts yet2s512 MBJudgeable
Minimum subarray averageFind the starting index of a length-two-or-more subarray whose average is smallest, breaking ties by smallest start.Medium6ArrayMath+1No attempts yet1s512 MBJudgeable
Mensa SafeEach grid cell points to another cell; find the start that visits all N*N cells exactly once before repeating, or report none or many.Medium6GraphSimulation+2No attempts yet2s512 MBJudgeable
A Garden with PondsGiven a small elevation grid, find the rectangular pond whose border cells all exceed its interior cells, maximizing the total water it can hold.Medium6Brute forceImplementation+2No attempts yet2s512 MBJudgeable
Abandoned AnimalGiven each store's stock and the ordered list of purchases, count how many store assignments make store numbers nondecreasing: zero, one, or many.Medium6GreedyArray+1No attempts yet2s512 MBJudgeable
Galactic Collegiate Programming ContestAfter each of m solve events, report the rank of team 1 among n teams ranked by solve count and then penalty.Medium6SortingBinary search+2No attempts yet5s512 MBJudgeable
A Strange TournamentGiven a sequence of distinct powers, choose a non-crossing knockout bracket minimizing the total absolute difference over all matches played.Medium6Dynamic programmingDivide and conquer+2No attempts yet2s512 MBJudgeable
Card block reversalGiven a permutation of 1..N, choose one contiguous block to reverse so that the final number of positions i with card i is maximized, breaking ties by leftmost start then leftmost end.Medium6ArrayHash map+1No attempts yet1s128 MBJudgeable
RoofGiven N column heights, pick a peak position and height so the roof shape h_j = peak - |peakpos - j| is positive everywhere, minimizing total absolute changes.Medium6ArrayPrefix sum+2No attempts yet1.5s128 MBJudgeable
SpiralsK spirals walk outward with run lengths 1,1,2,2,... on an N by M grid; for each cell print the earliest step any spiral reached it, within a 10^100 step limit.Medium6ImplementationSimulation+2No attempts yet1s64 MBJudgeable
My Cow Ate My HomeworkFor each prefix length K that the cow ate, compute the average after dropping the single lowest remaining score, and list every K that maximizes it.Medium6ArrayPrefix sum+2No attempts yet2s512 MBJudgeable
Minimum editCompute the Levenshtein distance between two lowercase strings, using the fewest insert, delete, and replace operations to change A into B.Medium6Dynamic programmingString+2No attempts yet2s512 MBJudgeable
Kindergarten candy bagsAssign N candy bags to N children to minimize the largest absolute difference between each child's candy and the candy of the child they picked; the picking forms a permutation.Medium6Binary searchGreedy+2No attempts yet2s256 MBJudgeable
Array Manipulation at Moloco (Hard)For each position i in a permutation-like array, count how many earlier elements are smaller than A[i], with n up to one million.Medium6Segment treeBinary search+2No attempts yet2s512 MBJudgeable
Prime-Factor PrimeCount integers in [l, r] whose number of prime factors counted with multiplicity, written Omega(n), is itself prime.Medium6Number theoryMath+2No attempts yet2s512 MBJudgeable
Farmer Juan is a baristaMaintain a grid under range-add rectangle updates and point queries, answering each point query using only earlier updates.Medium6Prefix sumMatrix+2No attempts yet2s512 MBJudgeable
Two teams with the smallest ability gapSplit N people into two nonempty teams so the difference between the two teams' pairwise ability sums is minimized, and print that minimum.Medium6Bit manipulationBrute force+2No attempts yet2s512 MBJudgeable
Stacking dicePartition N dice into the fewest towers, where a tower lists dice top to bottom so the i-th die has at most s_i dice above it.Medium6GreedySorting+2No attempts yet2s512 MBJudgeable
Escape RoomEach press toggles one button and up to two buttons to its right; find the fewest presses to turn an all-off row of N lights into a target 0/1 pattern.Medium6GreedyArray+2No attempts yet1s256 MBJudgeable
ReversingGiven prefix or suffix reversals applied to an array, track where the element originally at position K ends up after all operations.Medium6ArrayImplementation+2No attempts yet2s512 MBJudgeable
Ukje and MysophobiaSort a permutation of 1 to N by repeatedly reversing intervals, using at most N*N reversals to make card i sit at position i.Medium6ArraySorting+2No attempts yet2s256 MBJudgeable
Building a SpaceshipPartition the ordered parts into contiguous groups, paying for each group the product of its maximum weight and maximum energy; minimize the total cost.Medium6Dynamic programmingArray+2No attempts yet2s512 MBJudgeable
Origami, or the Art of Folding PaperFold a rectangle several times along axis-aligned lines, punch holes in the folded stack, and count how many holes each punch makes in the unfolded sheet.Medium6SimulationImplementation+2No attempts yet2s512 MBJudgeable
Down the PyramidCount non-negative integer sequences of length n+1 lying under a given length-n sequence, where each adjacent pair sums to the number above it.Medium6MathImplementation+2No attempts yet2s512 MBJudgeable
Lush GearsPick one model per gear type so the total cost is as close to C as possible without exceeding it, and report the leftover coins.Medium6Dynamic programmingArray+1No attempts yet2s512 MBJudgeable
Chinese ID NumberCheck an 18-character Chinese ID: region code from a given list, birthday in 1900 to 2011, sequence code not 000, then for valid IDs report gender by odd/even sequence code. The checksum is a mod 11 weighted sum of the first 17 digits plus a digit x making the total 1, with x=10 written as 'X'.Medium6StringArray+2No attempts yet2s512 MBJudgeable
Birthday BoyGiven colleagues' birthdays on a non-leap calendar, pick a date not used by anyone that maximizes the gap just before it, breaking ties toward the earliest date after October 27.Medium6ArraySorting+2No attempts yet1s512 MBJudgeable
CircuitsGiven axis-aligned rectangles, choose two horizontal lines to maximize how many distinct rectangles they touch along a top or bottom side.Medium6SortingArray+2No attempts yet2s512 MBJudgeable
ChainFor each position, repeatedly jump to the first strictly greater element on its right and report the length of that chain.Medium6StackDynamic programming+1No attempts yet2s512 MBJudgeable
Card GameMinsu holds M distinct blue cards and must answer each of K plays by discarding the smallest blue card larger than Cheolsu's card, or answering 0 when none exists.Medium6Binary searchGreedy+2No attempts yet1.2s512 MBJudgeable
Linked ListMaintain a permutation of 1..N under slide(a,b) moves (move a to just after b), reporting how far a moves each time and printing the final list.Medium6Linked listArray+2No attempts yet1s512 MBJudgeable
Substring PermutationGiven strings S and P, decide whether some permutation of P is a substring of some permutation of S.Medium6Hash mapTwo pointers+1No attempts yet1s512 MBJudgeable
The Good, the Great, and the SuperbGiven a sequence of digits, find the minimum number of elements to change so the sequence becomes Good, Great, or Superb, where Superb is constant, Great has adjacent gaps at most 1, and Good splits into Great or Superb blocks.Medium6Dynamic programmingGreedy+2No attempts yet1s512 MBJudgeable
JackRabbit SlimGiven sorted distinct carrot positions on a line, Slim repeatedly jumps to the nearest remaining carrot, breaking ties to the right; find the sum of total distances over all possible starting carrots.Medium6Dynamic programmingArray+2No attempts yet2s512 MBJudgeable
Arithmetic ProgressionsGiven up to 5000 distinct numbers, find the length of the longest subset that forms an arithmetic progression.Medium6ArrayHash map+1No attempts yet5s512 MBJudgeable
Colorful DrinkGiven colored liquids with densities and a top-to-bottom list of requested color layers, decide whether one liquid per layer has strictly decreasing densities.Medium6GreedyBinary search+2No attempts yet2s512 MBJudgeable
PalaceCount ways to place N non-attacking palace pieces (rook plus king moves) on an N by N board, modulo 1,000,000,007, for up to 1,000,000 test cases with N up to 10,000,000.Medium6MathCombinatorics+2No attempts yet2s512 MBJudgeable
Bitaro the BraveCount quadruples (i, j, k, l) with i<k and j<l such that grid cells (i,j)='J', (i,l)='O', (k,j)='I'. H, W up to 3000.Medium6Prefix sumArray+1No attempts yet1s512 MBJudgeable
Sleepy Cow SortingFind the minimum number of moves to sort a permutation, where each move takes the front element and inserts it k positions later, and output the move sizes.Medium6ArrayGreedy+2No attempts yet2s512 MBJudgeable
Painting the Barn (Silver)Given N axis-aligned rectangles with coordinates in 0..1000, find the total area covered by exactly K of them.Medium6Prefix sumArray+2No attempts yet2s512 MBJudgeable
Alice in the Digital WorldFind the maximum sum over subarrays whose minimum element equals m, given that the array and m are bounded by 26.Medium6ArrayDivide and conquer+2No attempts yet1s512 MBJudgeable
Moving a Pipe 1Count the ways to push a two-cell pipe (horizontal, vertical, or diagonal) across an N by N grid of walls until one end reaches (N, N).Medium6Dynamic programmingSimulation+2No attempts yet1s512 MBJudgeable
Hyper TomatoGiven an 11-dimensional grid of ripe, unripe, and empty cells, find the minimum days until every unripe tomato ripens, or -1 if some never do.Medium6BFSGraph+2No attempts yet1s512 MBJudgeable
Why the Cows Climbed onto the Information IslandOn a circle of N values, each query flips one value's sign; after every query print the sum of products over all N windows of four consecutive cows.Medium6ImplementationMath+2No attempts yet2s256 MBJudgeable
2D Array and OperationsSimulate up to 100 seconds of row-sorting or column-sorting on a 3x3 grid, where each sort replaces values by (value, frequency) pairs, and report when A[r][c] becomes k.Medium6SimulationImplementation+2No attempts yet0.5s512 MBJudgeable
Fishing KingA fisherman sweeps columns left to right, catching the lowest shark in each column while the rest slide and bounce vertically or horizontally, merging sharks that collide.Medium6SimulationImplementation+2No attempts yet1s512 MBJudgeable
Jealous TeachersEach of N-1 students must send exactly N-1 flowers to teachers they learned from, and every teacher must receive exactly N-1 flowers in total, or report that no such assignment exists.Medium6GraphImplementation+2No attempts yet3s1024 MBJudgeable
Cake CuttingGiven cut positions on a roll cake and several target piece counts, find the largest possible minimum piece length for each count.Medium6Binary searchGreedy+2No attempts yet1s512 MBJudgeable
Comparing StringsGiven two lowercase strings, align them by repeating characters of either string, keeping order, and minimize the sum of absolute alphabet-position differences over aligned pairs.Medium6Dynamic programmingString+2No attempts yet1s512 MBJudgeable
NautilusGiven an R by C water and island grid plus M move signals with wildcards, count how many cells can be the submarine's current position if it never enters an island.Medium6ImplementationSimulation+2No attempts yet2s512 MBJudgeable
SnakesSplit the sequence into K+1 contiguous segments, set each segment's net size to its maximum, and minimize the total sum of segment maxima minus the sum of all group sizes.Medium6Dynamic programmingArray+2No attempts yet2s512 MBJudgeable
Life GameSimulate Conway-style life on an N x M board for T steps using a (2K+1) square neighborhood with thresholds a and b, then print the final board.Medium6SimulationImplementation+2No attempts yet2s512 MBJudgeable
Almost-K Increasing SubsequenceFind the longest subsequence of a given sequence that has at most K positions where consecutive elements decrease.Medium6Dynamic programmingArray+2No attempts yet1s256 MBJudgeable
Tough GuyCount the cells reachable from a start on a grid where you move up and down freely but left and right at most L and R times total, with walls blocked.Medium6GraphBFS+2No attempts yet1s256 MBJudgeable
Rotating an ArrayGiven an odd n x n grid and a rotation angle that is a multiple of 45 degrees, shift the four lines (main diagonal, middle column, anti-diagonal, middle row) cyclically and print the resulting grid.Medium6ImplementationMatrix+2No attempts yet3s512 MBJudgeable
StockFind the shortest subarray whose sum minus y times its length is at least Z and whose length times y is at most X, breaking ties by the latest start.Medium6Sliding windowPrefix sum+2No attempts yet1s512 MBJudgeable
RGB Street 2Paint N houses in a cycle with three colors so that every adjacent pair differs, minimizing total cost.Medium6Dynamic programmingImplementation+2No attempts yet0.5s128 MBJudgeable
Rotate Array 4Try every order of up to 6 rotation operations on the grid and report the largest possible minimum row sum after all rotations.Medium6Brute forceBacktracking+2No attempts yet1s512 MBJudgeable
Count of Increasing SubsequencesCount the strictly increasing subsequences of length K in a sequence of N distinct values, reported modulo 1e9+7.Medium6Dynamic programmingBinary search+2No attempts yet1s512 MBJudgeable
SortingGiven N and M, construct a permutation of 1..N for which insertion sort performs exactly M shifts, or report that it is impossible.Medium6GreedySorting+2No attempts yet0.5s256 MBJudgeable
Saving the Ryan StatueChoose one integer point on each side of an N by N square to form a smaller rectangle, maximizing the total value of statues it covers, including those on its border.Medium6ArrayPrefix sum+2No attempts yet3s1024 MBJudgeable
Ringo and PermutationGiven N and K, construct a permutation of 1..N whose inversion count is exactly K, or report that none exists.Medium6GreedyArray+2No attempts yet1s256 MBJudgeable
Monument TourPick one eastbound row for the bus to travel; the cost is the horizontal distance across plus twice the vertical detours to visit every monument, and we minimize it.Medium6MathPrefix sum+2No attempts yet1s512 MBJudgeable
Count SquaresGiven coordinates of h horizontal and v vertical lines, count how many axis-aligned squares have all four sides drawn by those lines.Medium6ArrayHash map+2No attempts yet2s512 MBJudgeable
JOIOJIGiven a string of J, O, and I, find the longest contiguous substring with equal counts of all three letters.Medium6Prefix sumHash map+2No attempts yet1s512 MBJudgeable
New GameSimulate a board game where K stacked pieces move in numbered order and reverse, redirect, or merge based on cell color, and report the turn a stack reaches 4 pieces or -1.Medium6SimulationImplementation+2No attempts yet0.5s512 MBJudgeable
Automatic AccountantEach coin slides along a track and drops into the first slot whose width is at least the coin's thickness and whose trigger mass is at most the coin's mass; sum the drop positions.Medium6SortingBinary search+2No attempts yet2s512 MBJudgeable
GazzzuaGiven known future prices over N minutes, buy at most one coin per minute and sell any number at any time, maximizing total profit.Medium6GreedyImplementation+2No attempts yet1s256 MBJudgeable
Domino PredictionGiven XORs of consecutive domino numbers, answer queries for the XOR of positions x and y, or for the value at y when x holds d.Medium6Prefix sumBit manipulation+2No attempts yet1s256 MBJudgeable
Absolute GameAlice and Bob alternately delete elements from their own arrays until one element remains in each; Alice maximizes and Bob minimizes the final absolute difference.Medium6Game theoryGreedy+2No attempts yet1s256 MBJudgeable
One of EachGiven a sequence containing every value 1 to k at least once, find the lexicographically smallest subsequence that includes each value exactly once.Medium6GreedyStack+2No attempts yet2s512 MBJudgeable
PolygonGiven segment lengths, choose a subset to form a non-degenerate convex polygon (largest side must be smaller than the sum of the rest) and report the maximum total length, or 0 if impossible.Medium6GreedySorting+2No attempts yet1s512 MBJudgeable
Ggeureuda GimgganomGiven N rolls, cut K cm off each end (one end if shorter than 2K, discard if at most K), then find the largest piece length P so the trimmed rolls yield at least M pieces.Medium6Binary searchArray+2No attempts yet1.5s1024 MBJudgeable
Ramen Buying (Large)Buy A[i] ramen from each factory using single-factory, adjacent-pair, or triple deals, minimizing the total cost.Medium6GreedyImplementation+2No attempts yet1s64 MBJudgeable
Penguin Fall Response CommitteeGiven a line of N blocks with break costs and one marked penguin position, find the minimum total cost to break blocks so the penguin's group falls off the line.Medium6GreedyArray+2No attempts yet2s512 MBJudgeable
QuicksortSort an array using at most n steps, where each step swaps any disjoint set of adjacent pairs.Medium6SortingGreedy+2No attempts yet2s512 MBJudgeable
Football HooliganismPartition a 2 by N grid of team labels into non-overlapping rectangles so that every rectangle is monochromatic, minimizing the number of 1 by 1 rectangles.Medium6Dynamic programmingImplementation+2No attempts yet2s512 MBJudgeable
Swapity SwapStarting from cows labeled 1 to N in order, apply a fixed pair of range reversals K times and report the final order.Medium6SimulationMath+2No attempts yet2s512 MBJudgeable
Bubble Bucket SortPartition n bubble sizes into at most b buckets to minimize the sum of squared differences between the largest and smallest size in each bucket.Medium6Dynamic programmingSorting+2No attempts yet1s512 MBJudgeable
Hyper Array and Hyper QueriesGiven a value for every cell of an 11-dimensional array, answer range-sum queries over axis-aligned 11-dimensional boxes.Medium6Prefix sumArray+2No attempts yet2s512 MBJudgeable
Problem About Solving Problems (Dequery)Maintain a deque under queries that push the same value many times at either end, pop many elements, and read the k-th element; output each read.Medium6Linked listImplementation+2No attempts yet1s512 MBJudgeable
Social Distancing IGiven a binary string of occupied and empty stalls, place two new cows in empty stalls so the minimum distance between any two occupied stalls is as large as possible, and print that distance.Medium6GreedyBinary search+2No attempts yet1s512 MBJudgeable
Arithmetic SequencesGiven a set of distinct integers, find the size of the largest subset that can be ordered as an arithmetic sequence.Medium6Dynamic programmingSorting+2No attempts yet1.5s512 MBJudgeable
Three ArraysGiven three sorted arrays and a distance d, count triples of elements (one from each array) whose pairwise differences all stay within d.Medium6Two pointersSorting+2No attempts yet2s256 MBJudgeable
Subarray Average of a SequenceCount the contiguous subarrays of a given sequence whose elements have an average exactly equal to K.Medium6Prefix sumHash map+2No attempts yet1s256 MBJudgeable
Meeting Room Scheduling 2Given N meetings that overlap only with their immediate neighbors in the list, choose a non-overlapping subset maximizing total attendees.Medium6Dynamic programmingArray+2No attempts yet1s256 MBJudgeable