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,802 problems
TitleLevelTopicsSolvedTime limitMemory limitJudge
Arranging Go StonesStones are added one by one; each even-indexed stone of a new color replaces the trailing run of the opposite color, and we count the white stones that remain.Medium5StackSimulation+2No attempts yet1s128 MBJudgeable
Sum of a SequenceGiven an N by N table holding Ai+Aj for every pair of distinct indices and 0 on the diagonal, recover the original positive sequence A.Medium5MathArray+2No attempts yet1s256 MBJudgeable
Good NumbersCount the elements A_i that equal the sum of three elements appearing earlier in the sequence, where the same earlier element may be reused.Medium5Hash mapBrute force+2No attempts yet1s128 MBJudgeable
Klingon Course LevelsPick a score threshold T that splits every division into basic and advanced groups, minimizing the sum over divisions of |basic - advanced|. Output that minimum.Medium5SortingPrefix sum+2No attempts yet1s128 MBJudgeable
Pole PositionGiven the current race order of N cars with each car's position change from the start, reconstruct the starting grid or report that no valid grid exists.Medium5ArraySorting+2No attempts yet1s128 MBJudgeable
Bora BoraSimulate a children's card game with turn order, direction changes, forced draws and skips, and a fixed discard rule, and report the winner.Medium5SimulationImplementation+2No attempts yet1s128 MBJudgeable
SupermarketGiven a shopping list and products in path order, buy the list items in order from later positions at minimum total cost, or report impossible.Medium5Dynamic programmingArray+2No attempts yet1s128 MBJudgeable
BookshelfPartition the books in order into shelves whose widths sum to at most L, minimizing the total of each shelf's maximum height.Medium5Dynamic programmingArray+2No attempts yet1s128 MBJudgeable
IslandsGiven heights along a line, find the maximum number of separate exposed segments at any single rising water level.Medium5SortingArray+2No attempts yet1s128 MBJudgeable
Cow LineGiven N up to 20, convert between a permutation of 1..N and its lexicographic rank among all permutations, for up to 10000 queries.Medium5CombinatoricsMath+1No attempts yet1s128 MBJudgeable
Rubik's CubeSimulate Rubik's Cube face turns from an unfolded starting state and print the final facelet colors in the same layout.Medium5SimulationImplementation+2No attempts yet1s128 MBJudgeable
Switching LightsMaintain a binary array of N lights under M range-toggle and range-count operations, and print each query result.Medium5Segment treeArray+1No attempts yet1s128 MBJudgeable
Hay For SaleGiven a wagon capacity and a list of hay bale volumes, find the largest total volume not exceeding the capacity that can be formed by choosing whole bales.Medium5Dynamic programmingArray+2No attempts yet1s128 MBJudgeable
Patting HeadsEach of N cows has a value; for every cow count how many other cows hold a value that divides hers.Medium5MathNumber theory+2No attempts yet1s128 MBJudgeable
Sand CastleGiven current merlon heights and a multiset of target heights in any order, pair them to minimize the total cost of raising and lowering, where raising costs X and lowering costs Y.Medium5GreedySorting+2No attempts yet1s128 MBJudgeable
Cow CashCount the number of unordered ways to make an amount N using V coin denominations, where each coin can be used any number of times.Medium5Dynamic programmingCombinatorics+1No attempts yet1s128 MBJudgeable
Privileged CowsGiven a sequence of 1s, 2s, and 3s, find the minimum number of arbitrary swaps needed to group all 1s first, then all 2s, then all 3s.Medium5GreedyArray+2No attempts yet1s128 MBJudgeable
Charm BraceletChoose a subset of N charms, each with a weight and a desirability, so that total weight stays within M and total desirability is maximized.Medium5Dynamic programmingArray+2No attempts yet1s128 MBJudgeable
Balanced LineupGiven a static array of cow heights, answer queries giving the max minus min over each range [A, B].Medium5Segment treeArrayNo attempts yet1s128 MBJudgeable
Managing AllowanceFind the smallest fixed withdrawal amount K so that the N daily costs can be covered using exactly M withdrawals, counting forced top-ups and optional extra ones.Medium5Binary searchGreedy+2No attempts yet1s128 MBJudgeable
Chessboard DanceSimulate a beetle on an 8x8 board following move and turn commands, pushing chains of pieces that may fall off the board.Medium5SimulationImplementation+2No attempts yet1s128 MBJudgeable
El DoradoCount the increasing subsequences of length exactly k in a sequence of n distinct numbers, for several test cases.Medium5Dynamic programmingArray+1No attempts yet1s128 MBJudgeable
God Save the i-th QueenGiven a board and placed queens, count empty squares not sharing a row, column, or diagonal with any queen.Medium5ArrayHash map+2No attempts yet1s128 MBJudgeable
Railway TransportationSplit the arrival sequence into the fewest contiguous-order groups, each nondescending in arrival order, and report the count or failure if it exceeds M.Medium5GreedyBinary search+1No attempts yet1s128 MBJudgeable
Sea BattleCount rectangular ships of '#' cells on a grid, verify no two touch even diagonally, and report bad placement if the ships are not valid rectangles.Medium5ImplementationArray+2No attempts yet1s128 MBJudgeable
Pinball RankingGiven scores in play order, compute each game's rank as one plus the number of earlier-or-later scores strictly above it, then output the average rank as a reduced fraction.Medium5Binary searchSorting+2No attempts yet1s128 MBJudgeable
MõttemeisterGiven several guesses and their correct-digit counts A and position counts B, list every 4-digit secret number consistent with all clues.Medium5Brute forceImplementation+2No attempts yet1s1024 MBJudgeable
Sawtooth SequenceGiven N distinct numbers, arrange all of them into a zigzag sequence and output the lexicographically smallest such arrangement.Medium5GreedySorting+2No attempts yet1s1024 MBJudgeable
Repeated Permutation CipherGiven a permutation key and a repeat count k, apply the permutation to each padded message k times and print the result.Medium5ArrayImplementation+2No attempts yet1s128 MBJudgeable
Card Game CheaterEve knows Adam's card order and must permute her own cards to maximize the number of positions where her card beats his.Medium5GreedySorting+2No attempts yet1s128 MBJudgeable
False CoinGiven recorded balance weighings of N coins with exactly one false coin, output the coin number if the results identify it uniquely, otherwise 0.Medium5Brute forceImplementation+2No attempts yet1s128 MBJudgeable
Bin PackingPack items into identical bins holding at most two items each so that the number of bins is minimized.Medium5GreedyTwo pointers+2No attempts yet1s128 MBJudgeable
Catching FishGiven up to 100 fish on a large grid and a fixed net perimeter, find the placement of the net that covers the most fish.Medium5Brute forcePrefix sum+1No attempts yet1s256 MBJudgeable
FactoryGiven two orderings of the same N numbers, count pairs of connecting cables that cross when drawn as straight lines.Medium5SortingPrefix sum+1No attempts yet1s256 MBJudgeable
Arm Wrestling TournamentSimulate a single-elimination arm wrestling bracket of 2^N players where winners lose strength and recover K before each match; report the champion and the opponents beaten.Medium5SimulationImplementation+2No attempts yet1s128 MBJudgeable
Random GapGiven a linear congruential generator, find the largest gap between neighboring distinct values the sequence produces.Medium5SimulationHash map+2No attempts yet4s128 MBJudgeable
SkyscrapersFor each queried day, count maximal blocks of adjacent skyscrapers whose heights exceed the rising sea level.Medium5SortingArray+1No attempts yet2s128 MBJudgeable
SortingCount the swaps made by a given selection-style double loop on an array.Medium5SortingArray+1No attempts yet1s128 MBJudgeable
IslandGiven the edge lengths of a cycle, find the maximum over all pairs of towns of the shorter of the two arc distances.Medium5Two pointersPrefix sum+1No attempts yet3s512 MBJudgeable
InsulatorGiven n positive coefficients, reorder them so that the sum plus the total of positive rises between adjacent layers is as large as possible, and print that maximum.Medium5GreedySorting+2No attempts yet1s128 MBJudgeable
OrienteeringGiven the cyclic sequence of stage difficulties around a loop, decide whether some starting point and direction make the difficulties non-increasing.Medium5ArrayGreedy+1No attempts yet1s128 MBJudgeable
MapCount the marked points that have at least one point strictly below-left, above-right, below-right, and above-left of them.Medium5SortingArrayNo attempts yet1s128 MBJudgeable
Apples and Apple TreesGiven positions of n trees and m apples on a line, find the minimum distance from any apple to its nearest tree.Medium5SortingBinary search+2No attempts yet1s128 MBJudgeable
EncyclopediaGiven a stack of n pages and n sleeves, swap adjacent elements to make the two types alternate, and output the minimum number of swaps.Medium5GreedyArray+2No attempts yet1s128 MBJudgeable
Viewing TerracesIn a chain of terraces where climbing up costs height difference and descending is free, find the most distinct terraces reachable on k credits without returning to ground.Medium5Sliding windowTwo pointers+1No attempts yet1s128 MBJudgeable
ButtonsSimulate single counter increments and global max-fill operations to find the final counter values.Medium5SimulationArrayNo attempts yet1s512 MBJudgeable
Car WorkshopsCars pass through workshops in order and each one repaints color a to b on a match, so compute every final color.Medium5SimulationArrayNo attempts yet1s512 MBJudgeable
DistanceChoose two array elements, possibly the same element twice, to maximize the sum of the two values plus the distance between their positions.Medium5GreedyArrayNo attempts yet1s128 MBJudgeable
CitiesCount for each city on a directed line how many other cities are reachable through one-way and two-way roads.Medium5ArrayPrefix sumNo attempts yet1s128 MBJudgeable
ChildrenGiven a permutation on n cells, find the fewest adjacent swaps so every walk visits all cells.Medium5GraphArrayNo attempts yet1s128 MBJudgeable
WatchtowersFind the maximum sum over any nonempty block of consecutive towers arranged in a circle.Medium5Dynamic programmingArrayNo attempts yet1s128 MBJudgeable
More Garden TroublesFind the fewest flamethrower shots that clear every plot when each shot halves a plot and its two neighbors, rounding down.Medium5GreedyMath+1No attempts yet2s128 MBJudgeable
Math NotebookChoose a contiguous block from both sequences to maximize its dot product with the reversed second block.Medium5Brute forceArrayNo attempts yet1s128 MBJudgeable
Canoe AthletesPick one weight from each of four lists so the total is closest to the target, preferring the smaller total on ties.Medium5Binary searchSorting+1No attempts yet3s256 MBJudgeable
Mod-3 PermutationCount entries by index and value residues mod 3, fix directly swappable pairs first, then resolve each leftover triple with two swaps.Medium5GreedyMath+1No attempts yet1s128 MBJudgeable
Global WarmingGiven column heights, find the greatest number of maximal above-water runs over all real sea levels.Medium5Union-findSorting+1No attempts yet2s512 MBJudgeable
BaumkuchenSplit the circular cake into three contiguous pieces so the smallest piece is as large as possible.Medium5Binary searchTwo pointers+1No attempts yet2s256 MBJudgeable
VacationFrom a start city on a line with a fixed day budget where each move or city visit costs one day, pick the contiguous block with the most attractions.Medium5Two pointersPrefix sum+1No attempts yet5s64 MBJudgeable
Fuleco and the AntGiven positions A and B and a U/D string encoding depth changes along a tree walk, output the tree distance between the two forks.Medium5TreePrefix sum+1No attempts yet1s64 MBJudgeable
Salad BarFind the longest contiguous block of apples and oranges where oranges never fall behind apples when added from either end.Medium5Prefix sumStack+1No attempts yet3s256 MBJudgeable
EquatorEach test case gives city profits around a circle and asks for the most profitable contiguous block, or zero when all are losses.Medium5Dynamic programmingArrayNo attempts yet1s256 MBJudgeable
Cow JogCount the groups of cows that end at the same position after T minutes when no cow can pass the cow ahead.Medium5GreedyArrayNo attempts yet1s256 MBJudgeable
Honey Butter ChipArrange the M extra bags within the N fixed bags and pick no two adjacent bags to maximize the chip total.Medium5Dynamic programmingArrayNo attempts yet5s256 MBJudgeable
Maximize DifferencesReorder the given array so the sum of absolute differences between neighbors is as large as possible.Medium5GreedySorting+1No attempts yet1s256 MBJudgeable
Counting Cafeteria MenusCount how many distinct dish sets appear when the current set of N out of M dishes shifts forward by one each meal.Medium5String matchingArray+1No attempts yet2s256 MBJudgeable
Car GameFind the first dictionary word that contains each three-letter plate as a subsequence, or report that none exists.Medium5String matchingArrayNo attempts yet2s256 MBJudgeable
Maximal AreaGiven N column heights, find the area of the largest rectangle formed by whole unit squares.Medium5StackArrayNo attempts yet2s256 MBJudgeable
Cube IV (Large)Find the longest run of consecutive room numbers placed in neighboring cells and report its starting number and length.Medium5Dynamic programmingGraph+1No attempts yet5s512 MBJudgeable
Theme Park (Large)Groups board a coaster holding at most k people in queue order and rejoin the back after riding, and R runs of earnings must be totaled.Medium5SimulationQueue+1No attempts yet5s512 MBJudgeable
Picking Up ChicksCount the fewest adjacent swaps so at least K chicks, slowed by slower chicks ahead, reach the barn by time T.Medium5GreedyArrayNo attempts yet5s512 MBJudgeable
Crazy Rows (Small)Given an N by N binary matrix, reorder the rows using adjacent swaps so each row's rightmost 1 is at or left of its position, minimizing swaps.Medium5GreedySorting+2No attempts yet5s512 MBJudgeable
Saving the Universe (Large)Given a query stream and a set of engines, choose which engine handles each query, never an engine matching the query, to minimize the number of switches.Medium5GreedyImplementation+2No attempts yet5s512 MBJudgeable
Legendary JBNUMaintain a set of integer keys with values, supporting insert, update-by-nearest-key, and query that prints the nearest key's value, -1, or ?.Medium5ArraySorting+2No attempts yet2s128 MBJudgeable
Roller CoasterFrom a sequence of column heights, delete columns so the survivors strictly decrease then strictly increase (either part may be empty); output the maximum number of survivors.Medium5Dynamic programmingArray+2No attempts yet1s128 MBJudgeable
SouvenirParticipants sit in a circle; stage t removes the t^3-th person counting clockwise from the current host, and you find the last survivor.Medium5SimulationQueue+2No attempts yet2s512 MBJudgeable
Intervals of Unique NumbersCount pairs (i, j) where the subarray from i to j has all distinct values, with N up to 100000.Medium5Two pointersSliding window+2No attempts yet1s32 MBJudgeable
Minimum SwapsGiven permutations A and B, find the minimum number of swaps within A that turn it into B.Medium5ArrayHash map+2No attempts yet1s64 MBJudgeable
Secret PasswordGiven two length-N sequences, decide whether one is a cyclic rotation of the other.Medium5String matchingArray+2No attempts yet1s64 MBJudgeable
Gas StationsGiven road lengths and per-city fuel prices on a line, buy fuel along the way to minimize the total cost of driving from the first city to the last.Medium5GreedyArray+2No attempts yet2s512 MBJudgeable
Water PumpPlace one pump in a cell, let water drain toward it from both sides, and find the cell that removes the most water.Medium5ArrayPrefix sumNo attempts yet2s512 MBJudgeable
Contiguous Sum 2Find the maximum contiguous subarray sum after optionally deleting at most one element from the sequence.Medium5Dynamic programmingArrayNo attempts yet2s512 MBJudgeable
Rouba-MonteSimulate a card game where players draw, steal montes, and discard mismatches; report the winners by monte size.Medium5SimulationImplementation+2No attempts yet1s512 MBJudgeable
Isosceles Cube TriangleGiven column heights, find the largest h such that some 2h-1 consecutive columns can all be reduced to the shape 1,2,...,h,...,2,1.Medium5ArrayBrute force+1No attempts yet1s512 MBJudgeable
Command HistoryGiven a sequence of positions in a command history, simulate running each command by the nearest occurrence and total the up-arrow presses needed.Medium5ArrayHash map+2No attempts yet1s512 MBJudgeable
Stock exchangeGiven daily prices and a fixed fee per buy, find the maximum total profit when holding at most one share at a time and each share must be sold later.Medium5Dynamic programmingGreedy+2No attempts yet1s512 MBJudgeable
Strange BarGiven N kettle volumes and K people, find the largest integer amount X such that the sum over all kettles of floor(volume / X) is at least K.Medium5Binary searchArray+2No attempts yet1s512 MBJudgeable
Making the Array PalindromicMerge adjacent elements (each merge sums them) so the resulting array reads the same forwards and backwards, using the fewest merges. All values are positive.Medium5Two pointersGreedy+2No attempts yet1s64 MBJudgeable
Project PanoptesGiven n brightness readings and a lower bound p, find the smallest k >= p such that some arithmetic progression with step k lands only on dim days, where dim means below 0.8 times the average; output -1 if none exists.Medium5ArrayBrute force+2No attempts yet2s512 MBJudgeable
RobotGiven a grid with obstacles, a start cell, and a fixed cycling order of the four directions, simulate the robot that moves straight until blocked and report where it stops.Medium5SimulationImplementation+2No attempts yet1s256 MBJudgeable
Key KnockingGiven a binary string of length 3n, greedily pick operations in each 3-bit block to reach a weight of at least 2n within n moves.Medium5GreedyImplementation+1No attempts yet1s512 MBJudgeable
Weird Measurements (Medium)Count the contiguous subarrays whose consecutive differences alternate in sign, with no zero differences allowed.Medium5ArrayTwo pointers+2No attempts yet2s512 MBJudgeable
Large Weird MeasurementsCount all contiguous intervals whose consecutive differences strictly alternate in sign, with any length-1 interval counting as weird.Medium5ArrayTwo pointers+2No attempts yet2s512 MBJudgeable
Broadcast TowerPlace a tower of height H in a row of buildings; a building west of it receives its signal if no taller building blocks the path. Maximize receivers.Medium5StackArrayNo attempts yet2s512 MBJudgeable
Reading ListTotal lifted books over a sequence of assignments, where each assigned book moves to the top of the tower.Medium5ArraySorting+2No attempts yet1s128 MBJudgeable
ĆevapiEach day a new raft joins; simulate Goran's run across both banks under L meters and report meters on each bank and the portions eaten.Medium5SimulationSorting+1No attempts yet3s128 MBJudgeable
SnakeSimulate snakes that move forward, or turn right then left, given a board with obstacles for T seconds.Medium5SimulationImplementation+1No attempts yet4s64 MBJudgeable
Banknotes and RouletteSplit banknotes so the two equal-sum groups leave the smallest leftover, then add half of twice that leftover to each person's total.Medium5Dynamic programmingArray+2No attempts yet2s512 MBJudgeable
Score of a SubsequenceFind the maximum over all contiguous subarrays of the weighted sum where the k-th element from the subarray start contributes k times its value.Medium5Dynamic programmingArray+2No attempts yet2s512 MBJudgeable
Company Culture 2Given a tree of boss relations, apply subtree-wide praise additions in real time and answer point total queries.Medium5TreeDFS+2No attempts yet5s512 MBJudgeable
TetrominoGiven an N x M grid of positive integers, place one of the 5 tetrominoes (with rotations and reflections) to maximize the sum of covered cells.Medium5Brute forceImplementation+2No attempts yet2s512 MBJudgeable