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
Book ClubGiven each of N cows' answers to NQ questions, count how many cows match all P given question-answer pairs simultaneously.Medium4Hash mapImplementation+2No attempts yet1s128 MBJudgeable
The Bovine Fire DrillSimulate cows on a circular ring of N chairs, each moving clockwise by its own number, and report the cow that ends the drill.Medium4SimulationImplementation+1No attempts yet1s128 MBJudgeable
Bessie's Weight ProblemGiven N haybale weights and a limit H, find the largest total weight at most H that can be formed by choosing each bale at most once.Medium4Dynamic programmingArray+2No attempts yet1s128 MBJudgeable
The Chivalrous CowFind the fewest knight-move jumps on an X by Y grid with obstacles to get from the start square to the hay bale.Medium4BFSGraph+2No attempts yet1s128 MBJudgeable
Cow PinballGiven a triangle of nail scores with R rows, find the maximum sum along a path from the top nail down to the last row, moving to one of the two adjacent nails below each step.Medium4Dynamic programmingArray+2No attempts yet1s128 MBJudgeable
Music NotesGiven note durations that divide a timeline into consecutive intervals, answer queries asking which 1-based note covers a given time. Use prefix sums and binary search.Medium4Prefix sumBinary search+2No attempts yet1s128 MBJudgeable
Selfish GrazingGiven N intervals, find the maximum number of intervals that can be chosen so that no two of them overlap.Medium4GreedySorting+2No attempts yet1s128 MBJudgeable
Find the Playing NoteGiven note durations that partition a timeline, answer queries asking which note covers a given beat by locating the prefix sum that brackets it.Medium4Prefix sumBinary search+2No attempts yet1s128 MBJudgeable
Chocolate BuyingGiven N chocolate types with a cost per piece and a number of cows wanting each, spend a budget B to satisfy as many cows as possible.Medium4GreedySorting+2No attempts yet1s128 MBJudgeable
Longest Contiguous SubsequenceGiven two integer sequences, find the length of the longest run of consecutive elements that appears in both.Medium4Dynamic programmingArray+2No attempts yet1s128 MBJudgeable
The Widest MountainGiven a sequence of heights, find the longest contiguous run that is non-decreasing then non-increasing; valleys are shared by both neighboring mountains.Medium4ArrayImplementation+2No attempts yet1s128 MBJudgeable
Mountain WatchingGiven a sequence of heights, find the longest consecutive block that rises (non-strictly) then falls (non-strictly), allowing a block that only rises or only falls.Medium4ArrayTwo pointers+2No attempts yet1s128 MBJudgeable
Cruel Math TeacherCompute N raised to the power P exactly, then print the result with 70 digits per line and no leading zeros.Medium4MathImplementation+1No attempts yet1s128 MBJudgeable
Look UpFor each cow, find the smallest index j > i with H_j > H_i, or print 0 if none exists.Medium4StackArray+1No attempts yet1s128 MBJudgeable
O Those FadsCows join a fad when its attractiveness L reaches their resistance; each joiner raises L by K. Count the final number of participants.Medium4SortingGreedy+2No attempts yet1s128 MBJudgeable
Bookshelf 2Given up to 20 cow heights and a target bookshelf height B, find the minimum amount by which some subset's total height exceeds or equals B.Medium4Brute forceBit manipulation+2No attempts yet1s128 MBJudgeable
Election TimeEach cow has first round votes A and second round votes B; the top K by A advance, then the one with the largest B among them wins. Output the winner's index.Medium4SortingArray+2No attempts yet1s128 MBJudgeable
Dining CowsGiven a sequence of 1s and 2s, find the minimum number of values to change so the sequence becomes nondecreasing.Medium4Dynamic programmingPrefix sum+2No attempts yet1s128 MBJudgeable
Long Distance RacingGiven a terrain string and per-unit times, find the farthest segment index k whose round-trip time stays within M seconds.Medium4ArrayPrefix sum+2No attempts yet1s128 MBJudgeable
Lake MakingApply each 3x3 stomp by flattening the block down to its maximum minus D, then sum water depth times 72*72 for squares below level E.Medium4SimulationImplementation+2No attempts yet1s128 MBJudgeable
Hungry CowsGiven a sequence of N cow brands, find the length of the longest strictly increasing subsequence in the given order.Medium4Dynamic programmingBinary search+2No attempts yet1s128 MBJudgeable
Word GamesGiven a rack of up to 10 letters with wildcards and a dictionary of up to 50000 words, print every dictionary word whose letters can be covered by the rack, in input order.Medium4ImplementationBrute force+2No attempts yet1s128 MBJudgeable
The Eating PuzzleGiven up to 21 bucket sizes and a calorie limit, choose a subset with the largest sum that does not exceed the limit.Medium4Brute forceBit manipulation+2No attempts yet1s128 MBJudgeable
The Bale TowerGiven up to 20 bales with distinct widths and breadths, find the longest chain where each bale is strictly smaller than the one below it.Medium4Dynamic programmingSorting+2No attempts yet1s128 MBJudgeable
Buy One Get One FreeBuy all N high quality bales, then pair as many of the M low quality bales as possible so each free bale is strictly smaller than its distinct high quality partner. Output N plus the maximum number of pairs.Medium4GreedySorting+2No attempts yet1s128 MBJudgeable
Word PuzzleGiven a letter grid and a list of words, find each word's starting cell and one of eight reading directions, choosing the earliest match by row, column, then direction.Medium4ArrayBrute force+2No attempts yet1s128 MBJudgeable
Optimal Array Multiplication SequenceGiven the dimensions of a chain of matrices, find the minimum number of scalar multiplications needed to compute their product.Medium4Dynamic programmingMatrix+2No attempts yet1s128 MBJudgeable
Transferable VotingSimulate an instant-runoff election with ranked ballots, discard invalid ones, eliminate lowest-vote candidates each round, and report the winner or the tied candidates.Medium4SimulationImplementation+1No attempts yet1s128 MBJudgeable
BorderGiven a counter-clockwise closed grid path, mark every square that lies outside the region and shares an edge with the path, then print the 32 by 32 bitmap.Medium4SimulationImplementation+2No attempts yet1s128 MBJudgeable
M*A*S*HSimulate a card-driven counting-out lottery on a line of P people until X survivors remain, then print their original positions in increasing order.Medium4SimulationArray+2No attempts yet1s128 MBJudgeable
Message RoutingSimulate message routing through up to 10 MTAs whose tables use wildcards; report local delivery, routing loops, or unroutable messages.Medium4SimulationImplementation+2No attempts yet1s128 MBJudgeable
CowculationsFor each tablet, simulate three operations (add, shift right, shift left, or null) on a five-symbol cow number and check the padded result equals the eight-symbol line.Medium4ImplementationSimulation+2No attempts yet1s128 MBJudgeable
Diplomatic LicenseGiven an odd number of points around a circle, find for each adjacent pair the midpoint of the segment joining them, printed with six decimals.Medium4GeometryImplementation+2No attempts yet1s128 MBJudgeable
Suspicious StocksGiven daily stock prices and starting cash, buy as many whole shares as possible on one day, then sell all on a later day, and report the maximum profit.Medium4ArrayBrute force+2No attempts yet1s128 MBJudgeable
Stock ExchangeFor each issuer, for every bid output the agents on the opposite side whose price could match it, in input order.Medium4ArrayImplementation+2No attempts yet1s128 MBJudgeable
Calendar of EventsGiven old and new schedules of N meetings, simulate prefix reversals that place each target day and list the request sizes.Medium4SimulationImplementation+2No attempts yet1s128 MBJudgeable
Emag eht htiw Em PlehGiven White and Black piece lists, print the 8x8 chess board as ASCII art with alternating light and dark square fills.Medium4ImplementationSimulation+2No attempts yet1s128 MBJudgeable
The Idiot of the Year Contest!For each test case, count how many times a chosen digit occurs in the decimal representation of n! where n is at most 366.Medium4MathImplementation+2No attempts yet1s128 MBJudgeable
Expression EvaluatorEvaluate a C-style expression of letter variables with binary + and -, plus pre and post ++ and --, then report the result and each used variable's final value.Medium4StringSimulation+2No attempts yet1s128 MBJudgeable
The Happy WormCount maximal horizontal and vertical runs of empty cells that are at least 2 long in a field with stones.Medium4SortingImplementation+2No attempts yet1s128 MBJudgeable
Bridge TransportGiven car weights and a bridge that holds at most 4 cars, find the largest prefix that can cross without any window of 4 consecutive cars exceeding the weight limit.Medium4Sliding windowArray+2No attempts yet1s128 MBJudgeable
Keep on Truckin'Given fixed and added motel distances, count overnight stop sequences where each day covers between A and B km.Medium4Dynamic programmingArray+1No attempts yet1s128 MBJudgeable
OthelloSimulate up to 30 Othello moves on an 8x8 board starting from one of three configurations, then print the final black and white disc counts.Medium4SimulationImplementation+2No attempts yet1s128 MBJudgeable
Floor PlanGiven a grid of walls and floor cells, count connected rooms, sort them by size, floor as many of the largest rooms as the wood supply allows, and report how many rooms got flooring plus the leftover wood.Medium4DFSSorting+2No attempts yet1s128 MBJudgeable
Bridge CrossingSplit a line of people into consecutive groups of at most M, where each group costs its slowest member's time, and minimize the total cost.Medium4Dynamic programmingArray+2No attempts yet1s128 MBJudgeable
Long DivisionDivide a large integer by another using the schoolbook long-division method of shifting and repeated subtraction.Medium4MathImplementation+2No attempts yet1s128 MBJudgeable
Maximum DistanceGiven two non-increasing arrays, find the largest j - i such that j >= i and Y[j] >= X[i].Medium4ArrayTwo pointers+2No attempts yet1s128 MBJudgeable
SafebreakerGiven up to 10 guesses with correct-position and wrong-position digit counts, decide whether the secret 4-digit code is unique, impossible, or indeterminate.Medium4Brute forceImplementation+2No attempts yet1s128 MBJudgeable
Where's Waldorf?Given a grid of letters and a list of words, find the first-letter position of each word along any of eight straight directions, or the bottom-right cell if absent.Medium4ArrayString+2No attempts yet1s128 MBJudgeable
Grandpa's Lottery GamesGiven daily lottery spending and winnings, report the overall profit sign, the single day with the largest loss, and the consecutive run with the largest total loss.Medium4ArrayPrefix sum+2No attempts yet1s1024 MBJudgeable
Paper StripsStrips are glued on a black strip in order, each hiding what lies below; print the visible color and length of each final segment, merging equal neighbors.Medium4ImplementationArray+2No attempts yet6s1024 MBJudgeable
Overshadowed TreesFor each tree, check whether any taller tree within K positions exceeds its height by at least M, and list all such trees.Medium4Sliding windowArray+2No attempts yet1s1024 MBJudgeable
The RaceGiven the starting order of cars and a recorded list of adjacent overtakes, verify the sequence is valid and print the final order or the first impossible overtake.Medium4SimulationArray+2No attempts yet1s1024 MBJudgeable
House NumbersGiven add and remove sub-orders over ranges of house numbers, find the set of numbers kept and count how many of each digit 0 to 9 appear across them.Medium4ImplementationArray+2No attempts yet1s128 MBJudgeable
Rotten RopesGiven the tear-off weights of n ropes, find the maximum object weight that a chosen subset can carry so that no rope in the subset breaks.Medium4GreedySorting+2No attempts yet1s128 MBJudgeable
Grandpa's Other EstateGiven up to 100 points and a square side length r, place the axis-aligned square to cover as many points as possible, counting border points as inside.Medium4ArraySorting+2No attempts yet1s128 MBJudgeable
Lock ManagerProcess lock requests in order, granting an S or X lock when it conflicts with no granted lock, denying it and blocking the transaction otherwise, and ignoring later requests from blocked transactions.Medium4Hash mapSimulation+2No attempts yet1s128 MBJudgeable
On Storing ClothesSimulate a circular rail of hooks, depositing batches into the first fitting empty block and withdrawing them by ticket, printing freed hooks.Medium4SimulationArray+1No attempts yet1s1024 MBJudgeable
BowlingGiven the pins knocked down on each delivery of a valid ten-frame bowling game, compute the total score.Medium4SimulationImplementation+2No attempts yet1s128 MBJudgeable
BukazoidsGiven cell counts and a fixed number of single and double jumps, maximize collected bukazoids and output the lexicographically smallest optimal visit sequence.Medium4Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
Dart ChallengeFor each dartboard, count how many distinct total scores k darts can produce, where each dart misses or scores s_i, 2s_i, or 3s_i (no triple on the top area).Medium4Dynamic programmingArray+2No attempts yet1s128 MBJudgeable
TudokuFill in each 9x9 Sudoku board: whenever a row, column, or 3x3 block has exactly one empty cell, that cell is forced, and repeating this finishes every board.Medium4SimulationImplementation+2No attempts yet1s128 MBJudgeable
BrainmanGiven a sequence, find the minimum number of adjacent swaps needed to sort it in non-decreasing order; this equals the number of inversions.Medium4Divide and conquerSorting+1No attempts yet1s128 MBJudgeable
Boundless BoxesGiven a grid and up to 1000 seed cells, find the largest Chebyshev distance from any cell to its nearest seed, plus one.Medium4GeometryBrute force+1No attempts yet1s128 MBJudgeable
To Eat or Be EatenCount pairs where an A creature is strictly larger than a B creature, given two lists of sizes.Medium4SortingTwo pointers+2No attempts yet1s256 MBJudgeable
Minimum SwapsFor each string of distinct lowercase letters, find the minimum number of arbitrary swaps needed to sort it into alphabetical order.Medium4SortingGreedy+2No attempts yet1s128 MBJudgeable
Sultan's LandGiven P pillars on an N by N grid, count how many sets of four pillars form the corners of an axis-aligned rectangle.Medium4ArrayHash map+2No attempts yet1s128 MBJudgeable
Longest Ordered SubsequenceGiven a sequence of N integers, find the length of the longest non-decreasing subsequence.Medium4Dynamic programmingArray+2No attempts yet1s128 MBJudgeable
CannonsFor each query, report the minimum and maximum value in the given subarray of cannon strengths.Medium4Segment treeArrayNo attempts yet1s128 MBJudgeable
Neighbouring TownsGiven a symmetric shortest-distance table for n towns, list every pair A,B such that no third town C satisfies dist(A,B) = dist(A,C) + dist(C,B).Medium4ArrayBrute forceNo attempts yet1s128 MBJudgeable
CanoesGiven a canoe weight limit and each participant's weight, find the minimum number of two-person canoes needed to carry everyone.Medium4GreedyTwo pointers+2No attempts yet1s128 MBJudgeable
ImprovisationGiven a chord progression and a melody with pauses, remap each played note to the nearest note in the current chord's scale, advancing the chord every fourth position.Medium4SimulationImplementation+2No attempts yet1s128 MBJudgeable
DrawersPush as few drawers in as possible so the pull-out lengths strictly increase from the top drawer down.Medium4GreedyArrayNo attempts yet1s128 MBJudgeable
MatchesStarting from one match, fire spreads to each neighbor no taller than the burning match, and the task asks for the largest group that can burn.Medium4Dynamic programmingArrayNo attempts yet1s128 MBJudgeable
Gathering MushroomsChoose the earliest day t of at least 1 that maximizes the total weight of mushrooms still edible, where each weight grows daily.Medium4Prefix sumArrayNo attempts yet1s128 MBJudgeable
The Birthday PartyFind the smallest guest count m so that every candy pile leaves at least one leftover when divided equally among m guests.Medium4Number theoryArrayNo attempts yet1s128 MBJudgeable
Recursive Pattern (Szlaczek)Given a starting sequence that is repeatedly extended by appending its own reversal, report the value at position M.Medium4RecursionArray+1No attempts yet1s128 MBJudgeable
StickersPick stickers from a 2 by n grid with no two sharing an edge to maximize the total score.Medium4Dynamic programmingArrayNo attempts yet1s256 MBJudgeable
Diamond Mining ProfitsFind the contiguous period with the largest total gain across up to 2000 test cases, breaking ties by shorter length then earlier start.Medium4Dynamic programmingArray+1No attempts yet1s128 MBJudgeable
Colorful ChainCount the contiguous segments that hold exactly the required number of links of each listed color and no other colors.Medium4Sliding windowHash map+1No attempts yet3s512 MBJudgeable
Lottery 2Change as few entries as possible in a length-n sequence over 1 to k so no two adjacent entries are equal.Medium4GreedyArrayNo attempts yet1s128 MBJudgeable
Ranked ChoiceSimulate ranked-choice runoff with batch elimination and print each round until a majority winner emerges or no winner remains.Medium4SimulationArrayNo attempts yet60s256 MBJudgeable
Next permutationGiven a permutation of 1 to N, print the next permutation in lexicographic order, or -1 when the given one is the last.Medium4ArrayTwo pointersNo attempts yet1s256 MBJudgeable
Previous PermutationGiven a permutation of 1 to N, print the permutation that comes just before it in lexicographic order, or -1 when it is the first.Medium4ArrayNo attempts yet1s256 MBJudgeable
TelephonesAdd the fewest phones to empty desks so a ring hops from the first desk to the last with each hop spanning at most D.Medium4GreedyArrayNo attempts yet1s64 MBJudgeable
Mushroom Monster (Large)From plate counts taken every 10 seconds, compute the minimum mushrooms eaten under free eating and under the smallest consistent constant rate.Medium4GreedySimulation+1No attempts yet5s512 MBJudgeable
Climbing to the Information Science BuildingFind the crossing point k minimizing left-road distance from 1 to k plus crosswalk k plus right-road distance from k to n; output the smallest such k and the minimum distance.Medium4Prefix sumArray+2No attempts yet2s512 MBJudgeable
LiarsGiven a circular string of answers about whether the right neighbor is a liar, find the minimum number of liars consistent with all answers, or -1.Medium4Brute forceImplementation+1No attempts yet2s512 MBJudgeable
Important TestFor each variant, find the longest prefix solvable in t minutes given he may replace at most one task time with t0. Since order is fixed, choose the single task in that prefix whose copying saves the most time.Medium4ArrayPrefix sum+1No attempts yet2s512 MBJudgeable
Q-indexGiven n citation counts, find the largest k such that at least k papers have k or more citations and the rest have at most k.Medium4SortingArrayNo attempts yet1s512 MBJudgeable
Evenly Spaced TriplesGiven N distinct positions on a line, count how many triples of points have the middle point exactly halfway between the other two.Medium4Hash mapArrayNo attempts yet1s256 MBJudgeable
Minimum overtakesGiven a starting order and a finishing order of up to 24 cars, print the minimum number of adjacent swaps that turn the start into the finish.Medium4SortingArray+1No attempts yet2s512 MBJudgeable
Remove DuplicatesRead a space-separated list whose length is not given, keep each value only at its first occurrence, and print the surviving values in order.Medium4Hash mapArray+2No attempts yet5s8 MBJudgeable
Era NameGiven partial records mapping Western years to era names and regnal years, determine the era name and year for each query, or report Unknown when no record covers it.Medium4ArraySorting+2No attempts yet8s512 MBJudgeable
Pokemon TradingWith a fixed budget, buy on one day and sell on a later day to maximize profit; report the best result rounded to two decimals.Medium4ArrayGreedy+1No attempts yet0.3s4 MBJudgeable
Tandem BicyclePair each Dmojistan rider with a Pegland rider to minimize or maximize the sum of the larger speed in each pair.Medium4GreedySorting+2No attempts yet2s512 MBJudgeable
TunnelGiven the entry order and exit order of N cars through a tunnel, count how many cars must have overtaken another car.Medium4ArrayHash map+2No attempts yet2s512 MBJudgeable
Amusement Park QueueTwo people walk a fixed grid path one step per minute, offset by K minutes; count the minutes their cells touch in any of eight directions.Medium4SimulationImplementation+2No attempts yet1s128 MBJudgeable
Counting HaybalesGiven N distinct haybale positions and Q interval queries, count how many positions fall inside each inclusive range [A, B].Medium4SortingBinary search+2No attempts yet2s512 MBJudgeable
Box PackingGiven box sizes in order, find the longest subsequence where each box is strictly smaller than the next, counting boxes in the pile.Medium4Dynamic programmingBinary search+2No attempts yet2s512 MBJudgeable