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
Meeting Room Scheduling 3Choose non-overlapping meetings, where each meeting's time overlaps only its immediate neighbors in the input order, to maximize the total attendee count.Medium6Dynamic programmingGreedy+2No attempts yet1s256 MBJudgeable
The Last BattleA permutation a is fixed; rotating the identity arrangement right by k positions must satisfy a[i] != shifted value at each position. Find the smallest valid k, or -1.Medium6ArrayMath+2No attempts yet1s512 MBJudgeable
RobotGiven a sequence of signed step sizes, flip at most k signs to maximize the absolute value of the final position.Medium6GreedySorting+2No attempts yet2s512 MBJudgeable
Sequence TransformationGiven a sequence of non-negative integers, find the minimum number of single increments needed so that 1,2,...,h appear consecutively as a block, or report that it is impossible.Medium6ArraySliding window+2No attempts yet2s512 MBJudgeable
Minimal ProductGenerate a pseudorandom array and find indices i<j with a_i<a_j minimizing the product a_i*a_j, or report IMPOSSIBLE.Medium6ImplementationGreedy+2No attempts yet2s512 MBJudgeable
Currency ExchangeGiven n tablet values and an integer rate p, find two distinct indices i and j so that the ratio c_i / c_j is as close to p as possible.Medium6ArrayBinary search+2No attempts yet2s512 MBJudgeable
Stock King DonghoGiven prices for C stocks over D days and starting cash M, find the maximum cash obtainable by buying and selling whole shares each day using knapsack-style dynamic programming.Medium7Dynamic programmingArray+2No attempts yet2s128 MBJudgeable
Bubble SortGiven an array, compute how many bubble sort passes occur before no swaps happen, without simulating the O(N^2) sort directly for N up to 500,000.Medium7SortingSegment tree+2No attempts yet2s128 MBJudgeable
Dial LockGiven a current dial state and a password of N digits, find the minimum number of operations, each rotating a contiguous block of at most three circular dials by 1 to 3 steps, to reach the password.Medium7Dynamic programmingMath+2No attempts yet2s128 MBJudgeable
DNA ScoreGiven N equal-length DNA strings, design a symmetric, zero-sum score matrix with bounded entries to maximize the average pairwise alignment score.Medium7GreedyMath+2No attempts yet2s128 MBJudgeable
Deque SortGiven N integers in input order, assign each to a deque (front, back, or new deque) to minimize the number of deques whose concatenation can be sorted nondecreasing.Medium7GreedyBinary search+2No attempts yet2s128 MBJudgeable
Constructing a PermutationConstruct the lexicographically smallest and largest permutations of length N whose longest increasing and decreasing subsequences have exact given lengths M and K.Medium7CombinatoricsGreedy+2No attempts yet2s128 MBJudgeable
Farmland LevelingGiven N heights forming a 1D terrain, find the minimum number of unit cells to remove so that the number of resulting peaks is at most K.Medium7Dynamic programmingGreedy+1No attempts yet2s128 MBJudgeable
RainfallGiven partial yearly rainfall records, decide for each query whether a claimed record-rain statement between two years is definitely true, possibly true, or impossible.Medium7Binary searchArray+1No attempts yet2s128 MBJudgeable
Collecting GemsGiven N gem values, find a contiguous subarray of length at least M that maximizes floor(1000*sum/length), using binary search on the average.Medium7Binary searchPrefix sum+1No attempts yet2s128 MBJudgeable
Building a TournamentGiven a sequence of distinct ranks, build a bracket by repeatedly merging adjacent intervals (like matches in a tournament) minimizing the total sum of absolute rank differences over all merges.Medium7Dynamic programmingDivide and conquer+1No attempts yet2s128 MBJudgeable
Weakness in an Encryption AlgorithmGiven a sequence, decide if four indices p<q<r<s exist forming a specific interleaved value pattern, requiring an efficient algorithm beyond brute force for n up to 5000.Medium7Binary searchArray+2No attempts yet2s128 MBJudgeable
Turning Off StreetlightsFind the optimal order to switch off all streetlights on a line, starting from a given position, minimizing sum of power times shutoff time, a classic interval DP problem.Medium7Dynamic programmingGreedy+1No attempts yet2s128 MBJudgeable
Mischievous FrogsGiven how many frogs stepped on each of N field positions, reconstruct the minimum number of frogs, each following an arithmetic-progression path with step size at most 6, that reproduces the counts.Medium7GreedySimulation+1No attempts yet1s128 MBJudgeable
Descending-Run SortingGiven a permutation whose minimal slope decomposition always has even-length decreasing runs, simulate/derive how many reversal operations the described repeated slope-reversal sort performs until the array is sorted.Medium7ArraySimulation+1No attempts yet1s128 MBJudgeable
Walking TrailFor up to 100,000 rectangle queries over 300,000 points, count how many points lie exactly on the boundary of each axis-aligned rectangle.Medium7Prefix sumBinary search+1No attempts yet1s128 MBJudgeable
Median of a Contiguous SubsequenceCount odd-length contiguous subarrays of a permutation of 1..N whose median equals a given value B.Medium7Prefix sumHash map+1No attempts yet1s128 MBJudgeable
HousewarmingGiven a grid with blocked cells, find the maximum rectangle of empty cells and output twice its width plus height (the perimeter).Medium7Dynamic programmingStack+1No attempts yet1s128 MBJudgeable
Minimize the DifferenceGiven an array with a budget of T total decrements (each element bounded below by 1), reduce elements to minimize the maximum adjacent absolute difference and output the resulting array.Medium7Binary searchGreedy+1No attempts yet1s128 MBJudgeable
HighwayGiven a road profile and costs for flat, sloped, tunnel or viaduct travel, find the minimum time to cross using at most K equal-height shortcut structures.Medium7Dynamic programmingGreedy+1No attempts yet1s128 MBJudgeable
Non-boring SequencesDetermine whether every contiguous subarray of a sequence has at least one element unique within that subarray, using an efficient divide and conquer approach.Medium7Divide and conquerArray+1No attempts yet5s128 MBJudgeable
Unique Encryption KeysFor each of up to a million range queries over a sequence of keys, decide if the range has a duplicate and report the smallest repeated key value.Medium7Segment treeBinary search+2No attempts yet2s128 MBJudgeable
I-KeyboardPartition an ordered list of letter frequencies into K consecutive groups to minimize sum of frequency times in-group position, with a tie-break favoring later keys getting more letters, then output the resulting keyboard layout.Medium7Dynamic programmingGreedy+1No attempts yet1s128 MBJudgeable
AlibabaGiven points on a line with deadlines, find the minimum finishing time to visit all points starting from an optimally chosen point, respecting each point's deadline, or report impossibility.Medium7Dynamic programmingGreedy+1No attempts yet1s128 MBJudgeable
Non-monotonicityGiven a permutation of 1 to n, find the longest subsequence whose elements alternate down, up, down, starting with a decrease.Medium7Dynamic programmingArray+2No attempts yet10s128 MBJudgeable
CrabblesGiven a dictionary and hands of at most 10 lettered tiles with values, find the maximum-scoring dictionary word formable from each hand's tiles.Medium7TrieBacktracking+2No attempts yet1s128 MBJudgeable
'Roid RageGiven up to 10 simple polygons with integer vertices, report every pair that overlaps or touches, listing pairs in sorted order.Medium7GeometryImplementation+2No attempts yet1s128 MBJudgeable
Jumping BeansTrack how beans in a row are rearranged after T seconds of a wrap-around swapping process, printing the final order for each test case.Medium7SimulationMath+2No attempts yet1s128 MBJudgeable
Cookie SelectionProcess a stream of cookie insertions and median requests; each request outputs the upper median of the currently held multiset, supporting up to 600,000 operations.Medium7HeapImplementation+2No attempts yet1s128 MBJudgeable
Team DessertDesserts sit in a row; two alternating teams take from either end, and the first-picking team wants the smallest total weight it can guarantee against optimal play.Medium7Dynamic programmingGame theory+2No attempts yet1s128 MBJudgeable
Extreme Tic-Tac-ToeRead N-dimensional 3^N-cell tic-tac-toe boards (N up to 10) and count straight lines of three identical X or O symbols, ignoring lines with empty cells.Medium7ImplementationBrute force+2No attempts yet1s128 MBJudgeable
Segment PricingChoose a non-increasing fare for each boarding stop, with riders boarding only if their budget covers it, to maximize total revenue.Medium7Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
SortingGiven a permutation, find all gap sizes X for which repeatedly scanning and swapping positions i and i+X until a pass makes no swap leaves the array sorted.Medium7SortingArray+2No attempts yet0.3s64 MBJudgeable
Top 2000Partition a fixed sequence of singles into contiguous blocks, letting each block run under or over M minutes with per-minute penalties, and minimize the total penalty.Medium7Dynamic programmingPrefix sum+2No attempts yet1s128 MBJudgeable
NailsGiven up to 500000 upward triangles on a triangular grid of N nails per side, count the nails covered by at least one triangle.Medium7ArrayPrefix sum+2No attempts yet1s128 MBJudgeable
Candy Picking ContestChoose boxes in an M by N grid so no two chosen boxes touch vertically or horizontally, maximizing the total candies collected.Medium7Dynamic programmingGreedy+2No attempts yet1s256 MBJudgeable
Shrinking Inscribed PolygonGiven arc lengths around an inscribed polygon, find the minimum number of vertices to delete so the remaining vertices form a regular polygon, or report -1.Medium7Number theoryMath+2No attempts yet1s128 MBJudgeable
Turkish RoulettePlace B ordered balls into B non-overlapping pairs of adjacent wheel slots to maximize the dealer's profit, where each ball's value is its number times the sum of its two slots.Medium7Dynamic programmingArray+2No attempts yet3s128 MBJudgeable
Help-or-elseChoose an ordered subset of people to help; the finish time of each helper accumulates, and unhelped people add a penalty, so find the largest feasible subset under budget K.Medium7Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
The Suffering DwarvesMaintain a permutation under swaps and answer whether the set of heights A through B occupies consecutive positions.Medium7Segment treeArray+2No attempts yet1s512 MBJudgeable
Fuel EconomyFind the cheapest way to buy fuel along a route with a tank of capacity G, visiting stations with given prices, or report that the trip is impossible.Medium7GreedyStack+2No attempts yet1s128 MBJudgeable
Poker HandsGiven card counts per rank, find the fewest contiguous-rank straights whose unit cards sum to exactly those counts.Medium7GreedyArray+2No attempts yet1s128 MBJudgeable
SeatingTrack seats in a row under arrivals needing the lowest block of p empty seats and range departures; count the parties turned away.Medium7Segment treeBinary search+2No attempts yet1s128 MBJudgeable
Running LapsCount how many times a faster cow overtakes a slower cow, counting ordered pairs, before the fastest cow finishes L laps on a track of length C.Medium7SortingMath+2No attempts yet1s128 MBJudgeable
Haybale RestackingGiven N piles in a circle with current and target amounts of hay, move bales at cost equal to circular distance to reach the target with minimum total work.Medium7GreedyPrefix sum+2No attempts yet1s128 MBJudgeable
Cow PhotographsGiven a permutation of 1 to N, find the fewest adjacent swaps to reach a rotation of 1..N starting at some cow s, minimized over all s.Medium7ArraySorting+2No attempts yet1s128 MBJudgeable
BobsleddingBessie's speed changes by at most 1 per meter, turn i caps her speed at S_i when she passes marker T_i, and we want the highest speed she can reach anywhere on the course.Medium7GreedyImplementation+2No attempts yet1s128 MBJudgeable
The LeprechaunGiven an N x N matrix on a torus, find the contiguous circular run along any row, column, or either diagonal with the largest sum.Medium7ArrayDynamic programming+2No attempts yet1s128 MBJudgeable
Rooftop Garden BenchmarkingCount, over every building, how many strictly shorter buildings stand to its right before a building at least as tall blocks the view.Medium7StackArray+2No attempts yet1s128 MBJudgeable
Gold Balanced LineupGiven N cows each with a K-bit feature ID, find the longest contiguous range where every one of the K features appears the same number of times.Medium7Hash mapPrefix sum+2No attempts yet1s128 MBJudgeable
To the MaxFind the contiguous rectangular subregion of an N by N integer matrix with the largest possible sum and print that sum.Medium7Dynamic programmingArray+2No attempts yet1s128 MBJudgeable
Safe GamblingOn an odd circular wheel of N = 2K+1 priced pockets, choose three arcs of K consecutive pockets covering every pocket, minimizing the total sum of the arcs.Medium7ArraySliding window+2No attempts yet1s128 MBJudgeable
A Fair JuryPick exactly m candidates from a pool, minimizing |total defense minus total prosecution|, then maximizing the combined total among those juries.Medium7Dynamic programmingArray+2No attempts yet1s128 MBJudgeable
Biggest (Zero Carbon) FootprintGiven tree points in an n by m forest, find the largest axis-aligned rectangle with no tree strictly in its interior.Medium7GeometrySorting+2No attempts yet2s512 MBJudgeable
FirehosePlace k hydrants on a circle of circumference 1000000 so the largest arc-distance from any of H houses to its nearest hydrant is minimized, and report that distance.Medium7Binary searchGreedy+2No attempts yet2s512 MBJudgeable
WowowMaintain a dynamic set of (id, rating) friends under insertions, rating updates, and queries for the id holding the K-th highest rating.Medium7Segment treeBinary search+2No attempts yet2s512 MBJudgeable
ParadeMaintain a list of N perimeter-rotation commands on a 4x4 grid under Q cumulative point updates, printing the resulting grid after each update.Medium7SimulationImplementation+2No attempts yet1s128 MBJudgeable
Bowling for Numbers++Choose at most k windows of length w, possibly overlapping beyond the row ends, so the sum of the covered pins is as large as possible.Medium7Dynamic programmingPrefix sum+2No attempts yet1s128 MBJudgeable
Shopping OffersGiven regular item prices and bundle offers, find the minimum cost to buy exactly the listed quantities without buying extras.Medium7Dynamic programmingArray+2No attempts yet1s512 MBJudgeable
ProcessesGiven N queues of tasks, a limited number K of process splits, and one task completed per process per second, find the minimum time to finish all tasks.Medium7Binary searchGreedy+2No attempts yet1s1024 MBJudgeable
Illusive ChaseGiven a grid with obstacles and a log of chase trips, each recorded as a range of steps in one direction, count the possible starting cells consistent with the whole sequence.Medium7ArrayBrute force+2No attempts yet1s128 MBJudgeable
Longest Common Increasing SubsequenceGiven two integer sequences, find the length of the longest common increasing subsequence of both.Medium7Dynamic programmingArray+2No attempts yet1s256 MBJudgeable
CollisionsIdentical balls on a line move at constant velocities and swap velocities on elastic collision; count total collisions, or report infinity if unbounded.Medium7SortingMath+2No attempts yet1s128 MBJudgeable
WatchingChoose the smallest w so that P intervals of length w and Q intervals of length 2w together cover all given event sections.Medium7GreedyBinary search+2No attempts yet1s128 MBJudgeable
Connectivity of a Permutation GraphRead a permutation of up to one million elements and report the connected components of the graph joining i and j whenever i < j and a_i > a_j.Medium7StackGreedy+2No attempts yet2s256 MBJudgeable
RailwaysProcess train seat requests in order; accept a request only if every section it covers has enough free seats, and report T or N for each.Medium7Segment treeArray+2No attempts yet3s128 MBJudgeable
MonotonicityFind the longest subsequence of a sequence whose adjacent comparison symbols repeat a given pattern of <, >, = of length k.Medium7Dynamic programmingBinary search+2No attempts yet3s512 MBJudgeable
ShiftGiven a permutation of 1 to n, decide whether it can be sorted using only two moves: bring the last element to the front, or bring the third element to the front.Medium7ArrayImplementation+2No attempts yet1s128 MBJudgeable
Rearranging LettersGiven two equal-length anagrams, count the minimum adjacent swaps needed to turn the first string into the second.Medium7GreedySorting+1No attempts yet3s128 MBJudgeable
BanjoPick two separate one-minute intervals to maximize the number of people present for at least one full minute.Medium7ArraySorting+2No attempts yet5s128 MBJudgeable
Bytie's DisplayReorder the digits of a seven-segment display and flip at most n segments so the result reads as the lexicographically largest l-digit number.Medium7GreedyDynamic programming+1No attempts yet1s128 MBJudgeable
Variable SubsequencesCount distinct nonempty subsequences, identified by position sets, in which every two consecutive terms differ.Medium7Dynamic programmingCombinatorics+1No attempts yet2s512 MBJudgeable
PawnGiven a large board colored by row intervals, answer whether two squares lie in the same connected same-color region under 8-directional moves.Medium7Union-findIntervals+2No attempts yet1s192 MBJudgeable
Circular GameOn a circular board, white and black pieces slide over empty runs; decide with optimal play which side wins or whether play can go on forever.Medium7Game theoryArray+2No attempts yet1s128 MBJudgeable
BusesGiven bus timetables at every stop, pick an outbound bus and an inbound bus to minimize John's total waiting time before his friend arrives, returning by the friend's arrival time.Medium7SortingBinary search+2No attempts yet1s128 MBJudgeable
Ball Boxesn boxes in a row hold equal red and green balls with two adjacent empties; repeatedly move two balls into those empties and output a sequence that groups all reds before all greens.Medium7GreedySimulation+2No attempts yet1s128 MBJudgeable
Physical EducationJasio can skip up to k duels where he is the left student; find the leftmost final position he can reach.Medium7ArrayDynamic programming+2No attempts yet1s128 MBJudgeable
Land SwindleFor each meadow square choose at most one rectangle ending there, maximize the total perimeter, where each rectangle must contain only meadow squares.Medium7Dynamic programmingPrefix sum+1No attempts yet1s128 MBJudgeable
VacationChoose vacation days from a 3n-day forecast, taking at most k days in every window of n consecutive days, to maximize the total temperature.Medium7Dynamic programmingSliding window+2No attempts yet1s128 MBJudgeable
TowerPartition the sequence of brick widths into consecutive blocks so that block sums do not increase from bottom to top, maximizing the number of blocks.Medium7Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
Sunset Views 2For each point on an n by n grid, take the maximum building height within Manhattan distance k, then sum all these maxima.Medium7ArrayPrefix sum+2No attempts yet1s128 MBJudgeable
LinkNetGiven intervals on a line, schedule each transmission into a tick so that no interval in the same tick contains another interval's endpoint strictly inside it, and no point is used twice per tick; find the minimum ticks.Medium7IntervalsGreedy+2No attempts yet1s128 MBJudgeable
Cake PieceFind the k-th largest piece area after cutting a rectangle with n cuts in each direction.Medium7Binary searchSorting+2No attempts yet1s512 MBJudgeable
BytecomputerRepeatedly add an entry to its right neighbor in a -1, 0, 1 sequence to make it non-decreasing with the fewest operations, or report BRAK if impossible.Medium7Dynamic programmingArrayNo attempts yet3s512 MBJudgeable
Golf BotCount how many hole distances equal one dial distance or the sum of two dial distances.Medium7Divide and conquerMath+1No attempts yet1s256 MBJudgeable
Rotating the KeyringCount all wrong key tries made while doors 1 to N are unlocked in cyclic order K times with a rotating keyring.Medium7ArrayMath+1No attempts yet1s64 MBJudgeable
Unique right triangleCount the perimeters up to N that form exactly one integer-sided right triangle.Medium7Number theoryArray+1No attempts yet1s256 MBJudgeable
Spam FilterFind the contiguous block of at least k binary results with the highest share of ones, breaking ties by earliest start then shortest length.Medium7Binary searchPrefix sum+1No attempts yet1s256 MBJudgeable
ShufflesGiven a permutation of 1 to n, find the fewest riffle shuffles that can turn the sorted deck into it.Medium7MathArrayNo attempts yet2s256 MBJudgeable
Shortest Complete SubarrayProcess point updates on an array and report the length of the shortest contiguous subarray containing every value from 1 to K, or -1 if none exists.Medium7Segment treeSliding window+1No attempts yet3s512 MBJudgeable
What Are Birds? (Large)Given labeled points and the fact that birds are exactly the points in a height interval crossed with a weight interval, classify each query as always bird, never bird, or unknown.Medium7ArrayIntervals+2No attempts yet5s512 MBJudgeable
Gregory and the BankGiven fixed incoming and outgoing amounts plus a schedule of receiving and sending days, assign each transfer to a day to maximize suppliers paid.Medium7GreedySorting+1No attempts yet2s256 MBJudgeable
Train in a TunnelGiven car lengths and light states, find the minimum number of extra lights to turn on so that at every moment some lit car overlaps the tunnel.Medium7ArrayTwo pointers+2No attempts yet2s256 MBJudgeable
Problem PreparationMaintain an array under point increments and decrements, and after each update answer the sum of ceil(t_i / k) for a given k.Medium7MathPrefix sum+2No attempts yet2s256 MBJudgeable
Range XORMaintain an array under range xor updates and range xor queries, both on subarrays given by index bounds.Medium7Bit manipulationSegment tree+2No attempts yet2s512 MBJudgeable