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,779 problems
TitleLevelTopicsSolvedTime limitMemory limitJudge
Star FruitGiven summer length N, growth time T, C plots, and price P, compute the maximum money earnable by planting and replanting each plot as often as possible.Easy3GreedyMath+2No attempts yet1s256 MBJudgeable
Hamster BallTape can seal a ball only if its tape needed is at most the radius; each ball of radius s costs 2*pi*s, so pick sizes with the cheapest cost per ball.Easy3GreedySorting+2No attempts yet1s512 MBJudgeable
Climbing StairsGiven the required walk length n, the desk height r, and the office height k, find the minimum total steps walked in a day while starting and ending on the ground floor.Easy3MathImplementation+1No attempts yet1s512 MBJudgeable
Price EvaluationGiven property prices and a list of m property names where some entries are unknown, find the minimum and maximum possible total price.Easy3ImplementationGreedy+2No attempts yet2s512 MBJudgeable
Mountain RangesGiven non-decreasing viewpoint altitudes along a trail, find the length of the longest run where each consecutive altitude increase is at most X, starting anywhere.Easy3ArrayTwo pointers+2No attempts yet0.1s512 MBJudgeable
ZOAC 2A disk holds the 26 uppercase letters in a circle, and an arrow starts at 'A'. Find the minimum total rotations needed to print a given string in order.Easy3ImplementationGreedy+2No attempts yet1s512 MBJudgeable
Boxing Day Football AnalysisGiven the order of N goals scored by two teams, report the final score, the number of tied scores reached during the match, and the longest run of successive goals that flipped a deficit into a lead.Easy3SimulationImplementation+2No attempts yet1s512 MBJudgeable
BiodiversityGiven the species names of N animals, print the species that appears more times than all other species combined, or NONE.Easy3Hash mapImplementation+2No attempts yet3s512 MBJudgeable
Word ProcessorFormat N words into lines of at most K characters using the greedy first-fit rule, then print the result.Easy3SimulationImplementation+2No attempts yet2s512 MBJudgeable
Military ServiceEach soldier works at most K consecutive months then rests one month; find the largest number of soldiers that can be guaranteed on duty in every month.Easy3MathGreedy+1No attempts yet2s512 MBJudgeable
FeedbackBuild a strictly increasing length-N sequence with values at most 1000, second element 2, and last element prime.Easy3MathNumber theory+2No attempts yet1s512 MBJudgeable
SortingGiven a list of question difficulties, determine the minimum number of adjacent swaps needed to sort them into increasing order.Easy3SortingGreedy+1No attempts yet1s512 MBJudgeable
LunchBoxGiven N lunch boxes and each school's request ki, choose schools to satisfy fully (all ki boxes or none) so the count of served schools is maximized.Easy3GreedySorting+2No attempts yet0.5s512 MBJudgeable
Big Round TableMasha sits at a round table of n seats and makes exactly k swaps with a left or right neighbor; count the seats she could occupy at the end.Easy3MathGreedy+1No attempts yet1s512 MBJudgeable
SapsanGiven a row of n seats split into n/2 adjacent pairs, find the largest number of occupied seats so that exactly half the seated people sit next to an occupied neighbor.Easy3MathGreedy+1No attempts yet2s512 MBJudgeable
Attractive FlowersGiven the stock of each flower type, pick an odd count from each type so the total is odd and as large as possible.Easy3GreedyMath+1No attempts yet1s512 MBJudgeable
Maximum ProductSplit the array after one index so the product of the two part sums is maximized, and print that index.Easy3Prefix sumArray+2No attempts yet2s512 MBJudgeable
Room NumberGiven digit prices and a budget, find the largest possible room number (no leading zero unless it's just 0) that can be bought within the budget.Medium4GreedyString+1No attempts yet2s128 MBJudgeable
Line UpReconstruct a line of N people (heights 1..N) given for each height how many taller people stand to its left, using reverse insertion.Medium4ArrayGreedy+1No attempts yet2s128 MBJudgeable
AppointmentsGiven N pairs of appointment and arrival times, find how many integer shifts T minimize the total waiting time, which reduces to counting optimal medians of the differences.Medium4SortingMath+1No attempts yet2s128 MBJudgeable
Minimum Spanning TreeCompute the total edge weight of a minimum spanning tree for a weighted undirected graph with up to 10,000 vertices and 100,000 edges, allowing negative weights.Medium4Minimum spanning treeUnion-find+1No attempts yet1s128 MBJudgeable
Make a PalindromeRearrange the letters of a given uppercase string into the lexicographically smallest palindrome, or report it is impossible.Medium4StringGreedy+1No attempts yet2s128 MBJudgeable
Online Egg SalesGiven N eggs and M customers' maximum bid prices, pick the selling price (lowest if tied) that maximizes total revenue when all customers bidding at least that price buy an egg, capped at N sales.Medium4SortingGreedy+1No attempts yet2s128 MBJudgeable
Time ManagementGiven tasks with durations and deadlines, find the latest single start time so that all tasks scheduled back to back meet their deadlines, or report -1 if impossible.Medium4GreedySorting+1No attempts yet2s128 MBJudgeable
Word MathAssign distinct digits 0-9 to letters so that the sum of several words, read as base-10 numbers, is as large as possible.Medium4GreedyMath+1No attempts yet2s256 MBJudgeable
PolyominoCover every run of X cells with 2-cell (BB) and 4-cell (AAAA) blocks and print the lexicographically smallest resulting board, or -1 if some run has odd length.Medium4GreedyString+2No attempts yet2s128 MBJudgeable
Lecture RoomsGiven N lecture intervals, compute the minimum number of rooms needed so no room hosts overlapping lectures, treating touching endpoints as non-overlapping.Medium4GreedySorting+1No attempts yet2s128 MBJudgeable
Cable DonationGiven an adjacency matrix of cable lengths between rooms encoded as letters, find a minimum spanning tree and output the maximum total cable length that can be donated, or -1 if the rooms cannot all be connected.Medium4Minimum spanning treeGraph+2No attempts yet2s128 MBJudgeable
Number DecompositionGiven N up to 1,000,000, decompose it into nonnegative integers whose sum is N to maximize the product, then output that product mod 10007.Medium4MathGreedy+1No attempts yet2s128 MBJudgeable
FlippingGiven a binary string, find the minimum number of contiguous-segment flips needed to make all characters equal.Medium4StringGreedy+1No 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
Police StationsGiven a directed graph and per-city build costs, find strongly connected components and sum the minimum cost city in each component.Medium4GraphDFS+1No attempts yet2s128 MBJudgeable
Document SearchGiven a document and a word, find the maximum number of non-overlapping occurrences of the word within the document.Medium4String matchingGreedy+1No attempts yet2s128 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
Overlapping SegmentsGiven N line segments on a number line, compute the maximum number of segments that overlap at any single point, not counting endpoint-only contacts.Medium4IntervalsSorting+2No attempts yet2s256 MBJudgeable
Stack SequenceDetermine if a target permutation of 1 to n can be produced by a stack pushing values in increasing order, and output the push/pop sequence if possible.Medium4StackSimulation+1No attempts yet2s128 MBJudgeable
Network ConnectionGiven N computers and M weighted possible connections, compute the minimum total cost of edges to connect all computers into one network (minimum spanning tree).Medium4Minimum spanning treeUnion-find+1No attempts yet2s256 MBJudgeable
New EmployeesGiven N applicants ranked by two criteria, count applicants not dominated in both ranks by any other applicant (classic sort plus max-suffix pattern).Medium4SortingGreedyNo attempts yet2s256 MBJudgeable
CoinsGiven limited counts of coins worth 1, 5, 10, and 25 cents, find the combination summing to exactly X cents that uses the maximum total number of coins.Medium4GreedyBrute force+1No attempts yet2s128 MBJudgeable
Router InstallationGiven house coordinates, place C routers among them to maximize the minimum pairwise distance between chosen routers.Medium4Binary searchGreedy+1No attempts yet2s128 MBJudgeable
Post OfficeGiven villages with positions and populations on a line, find the point minimizing total weighted distance, choosing the smallest position on ties.Medium4SortingPrefix sum+1No attempts yet2s128 MBJudgeable
Cake DeliveryCompute the minimum total grid-walk distance to visit N customers in fixed order, where reaching any of the 4 neighbors of a customer point counts as delivery.Medium4GreedyMath+1No attempts yet2s128 MBJudgeable
Kimchi DeliveryGiven N cities on a line and a starting point, find the order of visiting all cities minimizing the sum of arrival times.Medium4GreedyDynamic programming+1No attempts yet2s128 MBJudgeable
Barn AssignmentGiven each cow's list of acceptable stalls, find the maximum number of cows that can be matched to distinct stalls using bipartite matching.Medium4GraphGreedyNo attempts yet2s128 MBJudgeable
SensorsGiven N sensor coordinates and up to K interval-shaped concentrators, find the minimum total interval length needed to cover all sensors.Medium4SortingGreedyNo attempts yet2s128 MBJudgeable
Choosing CondosCount condos that are Pareto-optimal, having no other condo that is both closer to the beach and cheaper.Medium4SortingGreedyNo attempts yet2s128 MBJudgeable
Find the Binary NumberGiven N, L, and I, output the I-th binary string of length N (with at most L ones) in increasing numeric order.Medium4CombinatoricsBinary search+1No attempts yet2s128 MBJudgeable
Building a TreeFind a spanning tree rooted at R that minimizes the sum of parent degrees over all non-root vertices, using a BFS-like greedy shortest path with degree as edge weight.Medium4Shortest pathGraph+1No attempts yet2s128 MBJudgeable
Guitar LessonSplit an ordered array into M contiguous groups so the maximum group sum is as small as possible, using binary search on the answer.Medium4Binary searchGreedy+1No attempts yet2s128 MBJudgeable
Maximum DistanceGiven up to 50,000 points, compute the maximum L1 (Manhattan) distance between any two of them.Medium4MathGreedy+1No attempts yet1s128 MBJudgeable
Three Numbers, Two MsGiven n integers, pick three to maximize 3 times (median minus mean), which reduces to sorting and checking min/max extremes.Medium4SortingGreedy+1No attempts yet2s128 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
PasswordGiven integer A, find the nearest smaller and nearest larger integers with the same popcount as A, using bit manipulation, or print 0 if none exists.Medium4Bit manipulationMath+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
Street TreesGiven sorted tree positions, find the minimum number of trees to insert so all consecutive gaps equal the GCD of all gap sizes.Medium4MathNumber theory+1No attempts yet1s128 MBJudgeable
Budget AllocationGiven budget requests and a total cap, find the maximum integer cap value such that capping requests at that value keeps the total within budget.Medium4Binary searchGreedyNo attempts yet1s128 MBJudgeable
Eating PancakesGiven a box A×B×C and D unit-thickness slices removed one dimension at a time, maximize the remaining volume by choosing which dimension to shrink each cut.Medium4GreedyMath+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
Amusement ParkGiven ride schedules with 10-minute buffers before and after each, find the longest free interval within 10:00-22:00 where no ride's blocked window overlaps.Medium4IntervalsSorting+1No attempts yet1s128 MBJudgeable
Stacking Colored PaperGiven N rectangles with allowed 90-degree rotation, find the longest chain where each sheet fits entirely inside the previous one.Medium4Dynamic programmingSorting+1No attempts yet1s128 MBJudgeable
Maximum Number of Noncrossing Circle ChordsGiven up to 50 chords on 100 circle points with distinct endpoints, find the maximum subset of chords with no two crossing.Medium4Dynamic programmingIntervals+1No attempts yet1s128 MBJudgeable
Next Greater NumberGiven a large number as a digit string, find the smallest permutation of its digits that is greater than it, or report BIGGEST if none exists.Medium4StringGreedy+1No 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
Number PlayFor each N, greedily factor it into digits 9 down to 2 to find the minimum digit count of a number whose digits multiply to N, or report -1 if impossible.Medium4GreedyMath+1No attempts yet1s128 MBJudgeable
ChainsGiven lengths of N chains, find the minimum number of links to open and close so that all chains merge into a single chain.Medium4GreedySorting+1No attempts yet1s256 MBJudgeable
Tree CuttingBinary search for the maximum saw height H so that trimming all trees above H yields at least M meters of wood total.Medium4Binary searchGreedyNo attempts yet1s256 MBJudgeable
Make the Largest NumberGiven an N-digit number, remove exactly K digits while keeping relative order to form the largest possible remaining number.Medium4StackGreedyNo attempts yet1s128 MBJudgeable
Apple Catching GameMove a fixed-size basket left or right along N cells to catch a sequence of falling apples with minimum total movement distance.Medium4Dynamic programmingGreedy+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
Kayaks and the Strong WindGiven broken and spare-carrying teams in a line, assign each spare kayak to an adjacent broken team to minimize the number of teams left unable to start.Medium4GreedyBrute force+1No attempts yet1s128 MBJudgeable
Three KangaroosGiven three sorted integer positions, compute the maximum number of jumps where an outer point can move to any free integer strictly between the other two.Medium4MathGreedy+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
DownloadGiven download times and playback durations of sequential song pieces, compute the earliest start time so playback never stalls waiting for a piece.Medium4GreedyPrefix sum+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
Division ExpressionGiven a left-to-right division expression of n positive integers, decide if some parenthesization yields an integer value, which reduces to checking if x1 times the product of x3..xn is divisible by x2.Medium4MathNumber theory+1No attempts yet1s128 MBJudgeable
ClassGiven n students and an r by c grid of desks, find the maximum achievable value k such that some row and some column can each have k occupied desks.Medium4MathGreedy+1No attempts yet3s256 MBJudgeable
The Bird TreeGiven a reduced fraction, reconstruct its path of L/R moves in the Stern-Brocot style Bird tree using a Euclidean-like process.Medium4MathGreedy+1No attempts yet1s128 MBJudgeable
MatchsticksGiven a number of matchsticks, find the smallest and largest positive numbers (no leading zero) that can be formed using exactly that many matchsticks based on per-digit costs.Medium4Dynamic programmingGreedy+1No attempts yet1s128 MBJudgeable
SongsGiven songs with lengths and play frequencies, sort them by length-to-frequency ratio (stable on ties) to minimize expected access time and report the song at a queried position.Medium4GreedySortingNo attempts yet1s128 MBJudgeable
Slim SpanGiven a weighted graph, find the spanning tree that minimizes the difference between its largest and smallest edge weight, or report -1 if disconnected.Medium4Union-findSorting+1No attempts yet2s128 MBJudgeable
Indiana Jones and the Lost Soccer CupGiven precedence constraints between levers, decide whether the order is unique; print the unique order, or report no order or multiple orders.Medium4Topological sortGraph+2No attempts yet1s256 MBJudgeable
Flash MobGiven n grid points, find the intersection minimizing the total Manhattan distance, breaking ties by smallest x then smallest y.Medium4SortingMath+2No attempts yet1s128 MBJudgeable
AlaskaGiven charging station positions along a 1422-mile highway and a 200-mile range, decide whether the round trip Dawson Creek to Delta Junction and back is possible.Medium4GreedySorting+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
Y2K Accounting BugGiven monthly surplus s and deficit d, find the maximum yearly total over all 12 months given that every 5-month block is negative, or report Deficit.Medium4Brute forceGreedy+1No attempts yet1s128 MBJudgeable
The TripGiven what each student spent, find the minimum total money that must change hands so every student ends up paying the same amount within one cent.Medium4GreedyMath+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
Jungle RoadsGiven a connected weighted graph of villages and roads, find the minimum total maintenance cost of a set of roads that keeps every village connected.Medium4Minimum spanning treeGraph+2No attempts yet1s128 MBJudgeable
RopesGiven pitch lengths of a climb, compute the maximum number of climbers for 50, 60, and 70 meter ropes, or 0 if a rope is unsuitable.Medium4SimulationGreedy+2No attempts yet1s128 MBJudgeable
Stable StringGiven a string of braces, find the minimum number of single-character flips that make all brackets correctly balanced.Medium4StackGreedy+2No attempts yet1s128 MBJudgeable
Money MattersGiven each person's balance and a friendship graph, decide whether all debts can be settled by moving money only within connected components.Medium4Union-findGraph+1No attempts yet1s128 MBJudgeable
DiscountsFor each product, given buy-B-get-F-free offers and query amounts, find the maximum saving in dollars for each quantity.Medium4Dynamic programmingGreedy+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