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,803 problems
TitleLevelTopicsSolvedTime limitMemory limitJudge
Greedily Increasing SubsequenceGiven a permutation, repeatedly take the leftmost unused element larger than the previous pick, and report the resulting subsequence.Medium4ArraySimulation+2No attempts yet1s512 MBJudgeable
Homework Never Ends!Each minute either adds homework (value A, work time T) or nothing; a new task preempts the current one, and finished tasks are submitted at the minute they finish. Sum the values of tasks completed within N minutes.Medium4StackSimulation+2No attempts yet2s256 MBJudgeable
Eeny MeenySimulate counting around a circle of kids with a rhyme length, removing one kid per round and assigning them to alternating teams.Medium4SimulationImplementation+2No attempts yet2s512 MBJudgeable
The New Year's BellGiven an N by M grid of who heard each bell ring, decide whether some distance thresholds R can produce exactly this pattern.Medium4SortingGreedy+2No attempts yet1s512 MBJudgeable
AntsGiven N integers, some negative or very large, find the smallest nonnegative integer that does not appear among the valid nonnegative values.Medium4ArrayHash map+2No attempts yet2s512 MBJudgeable
AntennaGiven positions of houses on a line, pick the house position that minimizes the total distance to all houses, choosing the smallest such position on ties.Medium4SortingMath+2No attempts yet1s256 MBJudgeable
Round TripA runner travels out and back along N courses given by their lengths; given total distance K, print which course the runner is on or about to enter.Medium4ArrayPrefix sum+2No attempts yet1s256 MBJudgeable
PhotoshootGiven adjacent sums b_i = a_i + a_{i+1} of a hidden permutation of 1..N, reconstruct the lexicographically smallest permutation a.Medium4Brute forceImplementation+2No attempts yet2s512 MBJudgeable
Arranging SoldiersGiven a sequence of N combat powers, find the minimum number of soldiers to remove so the remaining values are in strictly decreasing order.Medium4Dynamic programmingArray+2No attempts yet1s256 MBJudgeable
2048Simulate a sequence of 2048 moves, applying gravity, merging equal tiles once per move, and adding merge values to the score.Medium4SimulationImplementation+2No attempts yet2s512 MBJudgeable
EmacsCount the non-overlapping, non-touching rectangles of '*' characters in an N by M grid.Medium4ImplementationArray+2No attempts yet1s512 MBJudgeable
Maximum Subarray 2147483647Given a sequence of n integers, find the maximum possible sum of a contiguous subarray, choosing at least one element.Medium4Dynamic programmingArray+2No attempts yet2s512 MBJudgeable
Coordinate CompressionFor each of N coordinates, output the number of distinct values smaller than it, which is its rank under coordinate compression.Medium4SortingHash map+2No attempts yet2s512 MBJudgeable
LadderGiven n sticks that can only be shortened, decide whether two can become length x and k others length y.Medium4GreedySorting+2No attempts yet2s64 MBJudgeable
Frog 2Each frog ends at (a,b) after c unit steps on the grid; find the initial lattice point, or NO, choosing the smallest x then y.Medium4MathImplementation+2No attempts yet1s256 MBJudgeable
Best PlaceGiven N points, find integer coordinates (X, Y) that minimize the sum of Manhattan distances from the point to every participant.Medium4SortingMath+2No attempts yet1s512 MBJudgeable
Checking Answers to TestGiven the correct answers and each student's answers, find every pair of students whose correct and incorrect answers each match on more than half of the questions.Medium4Brute forceImplementation+2No attempts yet1s512 MBJudgeable
DunesEach gust adds +x to l and then alternates signs up to r; answer m queries for the final height at given positions.Medium4ArrayPrefix sum+2No attempts yet2s512 MBJudgeable
Misha's ProductGiven n distinct integers, concatenate every ordered pair of them and report the sum of all these concatenations modulo 1e9+7.Medium4MathArray+2No attempts yet1s512 MBJudgeable
High-Rise BuildingsGiven the heights of N buildings in a row, find the maximum number of other buildings visible in a straight line of sight from any single building.Medium5GeometryBrute force+2No attempts yet2s128 MBJudgeable
Lexicographically Largest SortGiven a distinct-integer array and a budget of at most S adjacent swaps, output the lexicographically largest array reachable within that swap budget.Medium5GreedyArray+1No attempts yet2s128 MBJudgeable
Hongjun Programming ContestGiven school sizes, choose a team size k to maximize k times the number of schools whose size is divisible by k, requiring at least two such schools.Medium5Number theoryMath+1No attempts yet2s128 MBJudgeable
Head TapsGiven N numbers arranged in a circle, count for each student how many other students' numbers it evenly divides using an efficient divisor-counting technique.Medium5Number theoryMath+2No attempts yet2s128 MBJudgeable
Good NumbersGiven N integers, count how many of them equal the sum of two other numbers at two different positions in the sequence.Medium5Two pointersArray+1No attempts yet2s256 MBJudgeable
Run, HongjunGiven N billboard intensities and a sight range M, output the maximum intensity within a sliding window of size 2M-1 for each valid position.Medium5Sliding windowQueue+1No attempts yet2s256 MBJudgeable
Fixed-Length Reversal SortGiven a permutation of up to 8 numbers, find the minimum number of fixed-length K reversals needed to sort it, or report impossibility.Medium5BFSGraph+2No attempts yet2s128 MBJudgeable
Tangled Electric WiresGiven a matching between left and right poles, find the minimum number of wires to cut so no two remaining wires cross, which reduces to computing N minus the longest increasing subsequence.Medium5Dynamic programmingBinary search+1No attempts yet1s128 MBJudgeable
Paper FoldingDecide whether a strip of N labeled cells can be folded so the stack reads 1 to N from top to bottom, checking labels against the shrinking strip's two ends.Medium5Two pointersSimulation+1No attempts yet2s128 MBJudgeable
String ExchangeGiven a circular string of a's and b's, find the minimum number of swaps to make all a's form one consecutive block.Medium5Sliding windowString+2No attempts yet2s128 MBJudgeable
Sejun and Sebi's WarGiven two armies whose weakest soldier dies each round (ties killing Sebi's soldier first), determine which side's soldier survives last.Medium5GreedySimulation+2No attempts yet2s128 MBJudgeable
Counting Crossing EdgesGiven M cross edges between two labeled vertex sets of size N, count how many unordered pairs of edges cross each other.Medium5SortingDivide and conquer+2No attempts yet2s128 MBJudgeable
Making the Best TeamChoose 15 players for white and 15 for black from a list of up to 1000 players to maximize the total ability sum.Medium5Dynamic programmingGreedy+1No attempts yet1s128 MBJudgeable
Chessboard in FENParse a chess position in FEN notation and count empty squares that are not attacked by any piece of either color.Medium5SimulationMatrix+2No attempts yet1s32 MBJudgeable
Making a PalindromeFind the minimum number of integers to insert into a sequence so it becomes a palindrome, using interval or LCS-based dynamic programming.Medium5Dynamic programmingArray+1No attempts yet2s128 MBJudgeable
Power Strip SchedulingSimulate plugging devices into a strip with N outlets and, when full, evict the device whose next use is farthest away (or never used again), counting total unplugs.Medium5GreedySimulation+1No attempts yet2s128 MBJudgeable
Number GroupingGiven N integers, decide which pairs to multiply instead of add so that the resulting total sum is maximized.Medium5GreedySorting+1No attempts yet2s128 MBJudgeable
Balanced LineupGiven fans sorted by x-coordinate with a gender bit each, find the longest contiguous segment that has an equal number of men and women.Medium5Prefix sumHash map+2No attempts yet2s256 MBJudgeable
Sorting the BookshelfFind the minimum number of single-book relocations needed to sort a permutation of N books into increasing order.Medium5Dynamic programmingArray+1No attempts yet2s128 MBJudgeable
Lexicographically Smallest Valid SequenceGiven a permutation S, construct the lexicographically smallest permutation T where each element differs from the corresponding S element by at most 1.Medium5GreedyArrayNo attempts yet1s128 MBJudgeable
Stacking BoxesSimulate stacking N axis-aligned boxes at given footprints using a 2D max-height map and report the final maximum height.Medium5SimulationArray+1No attempts yet3s128 MBJudgeable
Coin DistributionGiven several coin denominations with counts, decide for three test cases whether the coins can be split into two subsets of equal total value.Medium5Dynamic programmingArrayNo attempts yet2s128 MBJudgeable
Jump Jump ChampionshipGiven an array, find the longest strictly increasing subsequence and output its length plus the indices of one such subsequence.Medium5Dynamic programmingBinary search+1No attempts yet2s128 MBJudgeable
OmokSimulate placing stones in given order on a 19x19 Gomoku board and find the first move that creates exactly 5 in a row (not 6+) for its color.Medium5SimulationImplementation+1No attempts yet2s128 MBJudgeable
Interval Containing the Most OthersGiven N intervals with unique endpoints, find the maximum number of intervals strictly contained inside a single interval.Medium5SortingBinary search+1No attempts yet2s128 MBJudgeable
Bulbs and SwitchesGiven current and target bulb states, determine the minimum number of switch presses (each flipping a small neighborhood) needed, or -1 if impossible.Medium5GreedySimulation+1No attempts yet2s128 MBJudgeable
Sum of Subarrays from Two ArraysCount pairs of contiguous subarrays, one from each of two arrays, whose sums add up to a given target T.Medium5ArrayHash map+1No attempts yet2s64 MBJudgeable
Building a BridgeGiven a grid of land and sea, find the shortest straight sea-cell bridge connecting two different islands.Medium5BFSArray+1No attempts yet2s192 MBJudgeable
Number of RectanglesGiven up to 5000 points, count axis-aligned rectangles whose four corners are all present among the points.Medium5Hash mapCombinatorics+1No attempts yet2s128 MBJudgeable
Marbles in BoxesGiven two marble sequences and a pairwise score table, choose a sequence of pop/pop/pop-both operations to maximize total matched-pair score, using LCS-like DP with reconstruction.Medium5Dynamic programmingArray+1No attempts yet2s128 MBJudgeable
Team FormationPartition an age-ordered score sequence into contiguous groups to maximize the sum of each group's max-minus-min score.Medium5Dynamic programmingArray+1No attempts yet2s128 MBJudgeable
Sum of Three NumbersGiven up to 1000 distinct integers, find the largest set element expressible as a sum of three elements (repeats allowed).Medium5Two pointersSorting+1No attempts yet1s128 MBJudgeable
Buying JewelsFor each of n rows pick a contiguous non-empty subarray maximizing summed total value, breaking ties by fewest jewels then lexicographically smallest index sequence.Medium5Dynamic programmingArray+1No attempts yet2s128 MBJudgeable
Three SolutionsGiven up to 5000 distinct integers, find three distinct values whose sum is closest to zero, using sorting and two-pointer scanning.Medium5Two pointersSorting+1No attempts yet1s256 MBJudgeable
GemsGiven up to 100 diamond points on a grid, find the position of a fixed-size K by K square (axis aligned, within map bounds) that covers the maximum number of diamonds.Medium5ArrayBrute force+1No attempts yet1s128 MBJudgeable
Rotating SushiFind the maximum distinct sushi types among any k consecutive plates on a circular belt, adding one bonus for a given coupon type if not already present.Medium5Sliding windowHash map+1No attempts yet1s256 MBJudgeable
Colored Paper 3Given up to 100 aligned black 10x10 squares on a 100x100 grid, find the maximum area axis-aligned all-black rectangle.Medium5ArrayBrute force+1No attempts yet1s128 MBJudgeable
Corporate InvestmentAllocate exactly N integer units of money across M companies using given profit tables to maximize total profit, then output an allocation, a classic knapsack-style DP task.Medium5Dynamic programmingArray+1No attempts yet1s128 MBJudgeable
Digital TVCompute the minimum button presses to move KBS1 to position 1 and KBS2 to position 2 in a channel list using arrow move and swap operations.Medium5GreedySimulation+1No attempts yet1s128 MBJudgeable
Viewership Popularity SurveyGiven N viewing intervals (possibly wrapping past midnight) over a day, use a difference array over seconds to answer Q sum-of-popularity queries divided by interval length.Medium5Prefix sumArray+1No attempts yet1s128 MBJudgeable
Dongjun's GameGiven N level scores, find the minimum total decrease needed to make the sequence strictly increasing while all scores stay positive.Medium5GreedyArray+1No attempts yet1s128 MBJudgeable
Array Not Divisible by ThreeRearrange an array so no two adjacent elements sum to a multiple of 3, or report impossibility.Medium5GreedyMath+1No attempts yet1s128 MBJudgeable
AvogadroGiven a 3xN table where row 1 is a permutation of 1..N, find the minimum number of columns to delete so the three rows can be made identical after sorting each row.Medium5GreedyArray+1No attempts yet1s128 MBJudgeable
Popularity ListReconstruct the lexicographically smallest previous week's ranking consistent with UP/DOWN/SAME movement marks of this week's list.Medium5GreedyArray+1No attempts yet1s128 MBJudgeable
Cut and PasteSimulate K cut-and-paste block moves on an N-line document and report the first ten resulting line values.Medium5SimulationArray+1No attempts yet1s128 MBJudgeable
Complete the Sequence!Given a sequence known to fit a minimal-degree polynomial, use finite differences to extrapolate the next several integer values exactly.Medium5MathImplementation+1No attempts yet1s128 MBJudgeable
Defense of a KingdomGiven tower positions that block whole rows and columns on a grid, find the area of the largest rectangle of cells left undefended.Medium5SortingGreedy+1No attempts yet3s256 MBJudgeable
BureaucracyGiven a sequence of declare and cancel operations forming a chain, determine which laws remain active where a law is active only if no active law cancels it.Medium5SimulationImplementation+1No attempts yet3s256 MBJudgeable
ComputersGiven a fixed replacement cost and arbitrary maintenance costs for owning a computer over any year range, find the minimum total cost to cover n years using dynamic programming.Medium5Dynamic programmingArrayNo attempts yet1s128 MBJudgeable
Network ConnectionSimulate weighted union operations that always merge into the second cluster's center, and answer path-length queries to the current cluster center.Medium5Union-findImplementation+1No attempts yet1s128 MBJudgeable
Non-negative Partial SumsGiven a cyclic array, count how many rotations make every prefix sum of the rotated sequence non-negative.Medium5Prefix sumArrayNo attempts yet3s128 MBJudgeable
Bug HuntSimulate a small array based language line by line and report the first line where an out of range index or an unassigned array element is used.Medium5SimulationImplementation+1No attempts yet1s128 MBJudgeable
CounterattackTwo strikers advance in lockstep through n points, each step either dribbling or passing to the partner; find the cheapest route from a long pass at point 1 to a shot at point n.Medium5Dynamic programmingArray+1No attempts yet1s256 MBJudgeable
FlipperSimulate two-ended pile flips on a row of cards, then report the card number and orientation at queried positions.Medium5SimulationImplementation+1No attempts yet1s128 MBJudgeable
Buying GasChoose the fewest gas stations to stop at so the car never runs out of gas over a trip of length d with tank range 10n.Medium5GreedySorting+1No attempts yet1s128 MBJudgeable
Frosh WeekGiven n distinct student numbers in a line, find the minimum number of adjacent swaps needed to sort them into increasing order.Medium5SortingDivide and conquer+2No attempts yet1s128 MBJudgeable
Ferry Loading IIGiven car arrival times, ferry capacity n, and one-way time t, find the earliest finish time and the fewest one-way crossings to move all cars.Medium5GreedyImplementation+2No attempts yet1s128 MBJudgeable
Splitting Teams FairlySplit N people into two teams differing in size by at most one so their total weight difference is minimized, then print both totals in increasing order.Medium5Dynamic programmingArray+2No attempts yet1s128 MBJudgeable
Games R UsGroup users into equivalence classes by identical directory access sets, then report classes of size 2 or more.Medium5Hash mapSorting+2No attempts yet1s128 MBJudgeable
Rock SkippingFor each lake map, find the throw (start, skip distance) that maximizes count, then length, then start, then smallest distance, and print it.Medium5Brute forceImplementation+2No attempts yet1s128 MBJudgeable
Overflowing BookshelfSimulate a fixed-width shelf through add (push books leftward) and remove events; at End list the surviving books left to right.Medium5SimulationImplementation+2No attempts yet1s128 MBJudgeable
Board SillyGiven an 8x8 board of X and O pieces, list all legal moves for one player, where each piece moves exactly as many squares as pieces line its direction.Medium5SimulationImplementation+1No attempts yet1s128 MBJudgeable
The Turn of the ShrewEach child's code must differ from the bitwise OR of some male and female adult code; find the minimum Hamming distance over all pairs.Medium5Bit manipulationBrute force+2No attempts yet1s128 MBJudgeable
Fuel StopsFind all valid starting cities in a circular tour where fuel supply matches demand, and the tank never goes negative.Medium5GreedyPrefix sum+1No attempts yet2s128 MBJudgeable
RailroadGiven two sequences, decide whether a target sequence can be formed by repeatedly taking the front car of either train; once one train empties, the rest follow in order.Medium5Dynamic programmingTwo pointers+2No attempts yet1s128 MBJudgeable
ShufflingGiven a fixed permutation of N cards and a target order, find the minimum number of times to apply the permutation to reach the target, or -1 if impossible.Medium5MathNumber theory+2No attempts yet1s128 MBJudgeable
Rotating RingsGiven square grids, decide whether each can be turned into row-major sorted order using only independent rotations of each concentric ring.Medium5ArraySimulation+2No attempts yet1s128 MBJudgeable
Walk Like an EgyptianStones fill an N by N grid along a spiraling quarter-circle path; find the number placed in the top-right cell. Multiple N values per input.Medium5SimulationImplementation+2No attempts yet1s128 MBJudgeable
ShopaholicGiven item prices, group them into triples so that the cheapest item in each triple is free, and maximize the total discount.Medium5GreedySorting+2No attempts yet1s128 MBJudgeable
Rig PlacementGiven n oil fields, a per-field investment cap m, and a total budget B, pick an investment amount for each field so total oil is maximized.Medium5Dynamic programmingArray+2No attempts yet1s128 MBJudgeable
Stimulus PackageChoose a subset of at most 20 projects within budget B whose combined jobs meet every yearly target, maximizing total infrastructure gain.Medium5Brute forceImplementation+2No attempts yet5s128 MBJudgeable
Overlap!Given each course's exam day and time slot and each student's course list, count students who have two or more finals that overlap in time.Medium5ImplementationSorting+2No attempts yet1s128 MBJudgeable
Study DaysDistribute H study hours among n courses, each with 10 grade thresholds, to maximize the average grade point, rounded to two decimals.Medium5Dynamic programmingArray+2No attempts yet1s128 MBJudgeable
GerrymanderingSplit n precincts, each with P and Q vote counts, into two nonempty districts; find how many districts P can win (0, 1, or 2).Medium5Dynamic programmingArray+2No attempts yet1s128 MBJudgeable
And the Winner IsEach ballot has one character per candidate; discard any ballot that marks more than one candidate in the same race, then report the top vote-getter (ties included) in every race, in input order.Medium5ImplementationArray+2No attempts yet1s128 MBJudgeable
BallsThere are n balls and n holes. Balls fall straight down from (i,h) to holes at (i,0). Placing exactly one obstacle (a segment between two integer columns) that tilts right redirects all balls in its column range to its right (lower) end; tilting left redirects them to its left (lower) end. For each orientation, maximize the total score over all valid placements (both orientations must be used, i.e., one obstacle of the specified tilt is mandatory, even if it reduces the total). Constraints n up to 3e5, c_i up to 1e9 in absolute value, so O(n log n) or O(n) required, answers in 64-bit.Medium5ArrayPrefix sum+2No attempts yet1s128 MBJudgeable
Northwest WindCount pairs of islands where one can sail to the other moving only east or south (both coordinates monotone between the two points).Medium5SortingPrefix sum+2No attempts yet1s256 MBJudgeable
ImagineMaintain a 1024x1024 grid that starts as a checkerboard and process stickers plus rectangle queries for counts of each letter.Medium5Prefix sumArray+2No attempts yet1s256 MBJudgeable
JOIOI TowerGiven a string of J, O, I disks by increasing radius, find the maximum number of disjoint triples spelling JOI or IOI.Medium5GreedyArray+1No attempts yet1s128 MBJudgeable
FashionistaFor each day pick any clothing whose temperature range covers that day's high, maximizing the sum of absolute flashiness differences between consecutive days.Medium5Dynamic programmingArray+2No attempts yet1s128 MBJudgeable
Commute RouteCount monotone lattice paths from (1,1) to (w,h) that never turn at two consecutive intersections, modulo 100000.Medium5Dynamic programmingArray+2No attempts yet1s128 MBJudgeable