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 results288 problems
TitleLevelTopicsSolvedTime limitMemory limitJudge
Left and RightFind the lexicographically smallest permutation of 1..n whose consecutive moves match the given L/R string.Medium5GreedyStack+1No attempts yet2s512 MBJudgeable
Gahui's Remainder Sequence Game (Small)Maintain a sequence under push and pop from the back, and for each type-3 query report the shortest suffix whose values cover every residue 0 to mod-1, or -1 if impossible.Medium5StackArray+1No attempts yet1s256 MBJudgeable
Next Greater ElementFor each element of a sequence, output the nearest greater value to its right, or -1 if none exists.Medium5StackArray+2No attempts yet1s512 MBJudgeable
Frequency-Greater Next ElementFor each position, find the nearest value to its right whose total frequency in the array exceeds the frequency of the current element, or -1 if none exists.Medium5StackHash map+2No attempts yet1s512 MBJudgeable
Bracket SequenceEvaluate a bracket sequence where nesting alternates between addition and multiplication, printing the result modulo 10^9+7.Medium5StackImplementation+2No attempts yet2s512 MBJudgeable
Configuration FileParse a brace-delimited configuration file where assignments to variables are scoped to their block, and report the value assigned by each variable-to-variable assignment.Medium5StackHash map+2No attempts yet2s512 MBJudgeable
A Simple Sequence of DigitsGiven n and k, build the digit string formed by concatenating the first n primes, then delete exactly k digits to leave the largest possible number.Medium5GreedyStack+2No attempts yet1s512 MBJudgeable
Can You Do Arithmetic?Parse and evaluate an arithmetic expression with +,-,*,/ and parentheses, respecting precedence, and print ROCK if the expression is invalid or divides by zero.Medium6StringStack+2No attempts yet2s128 MBJudgeable
UndoSimulate a text editor whose undo command reverts every command from the previous t seconds, where undos themselves can be undone, and find the final text.Medium6StackSimulation+2No attempts yet2s128 MBJudgeable
Deleting DigitsGiven a digit string and a required count of each digit to delete, remove exactly that many occurrences of each digit to leave the numerically largest possible string.Medium6GreedyStack+2No attempts yet2s128 MBJudgeable
Largest Zero SubmatrixGiven a binary matrix, find the maximum area rectangle of consecutive rows and columns that contains only zeros.Medium6StackDynamic programming+2No attempts yet2s128 MBJudgeable
Flattening TablesParse nested HTML-style table layouts and output an equivalent single flat table using rowspan and colspan to preserve row and column alignment.Medium6RecursionTree+2No attempts yet1s128 MBJudgeable
HistogramGiven bar heights of a histogram, find the maximum-area rectangle that fits inside it using a stack-based approach.Medium6StackArray+1No attempts yet0.7s128 MBJudgeable
Card BundlesGiven a shuffled permutation of 1 to N, output N-1 adjacent merges that combine bundles into a single bundle where each intermediate bundle holds consecutive integers.Medium6StackGreedy+2No attempts yet2s128 MBJudgeable
Easy SkylineGiven the sequence of skyline breakpoints, find the minimum number of axis-aligned rectangular buildings that could produce that exact skyline.Medium6StackGreedy+1No attempts yet2s128 MBJudgeable
Choosing a Subarray 2Find a contiguous subarray maximizing (sum of elements) times (minimum element), and output that maximum score with the interval bounds.Medium6StackPrefix sum+1No attempts yet2s128 MBJudgeable
Choosing a SubarrayGiven an array, find the contiguous subarray that maximizes the product of its sum and its minimum element.Medium6StackPrefix sum+1No attempts yet2s128 MBJudgeable
Apple TreeGiven a DFS 0/1 traversal string of a tree and two marked positions, find the smallest subtree (by matching visit/return indices) that contains both marked vertices.Medium6TreeStack+1No attempts yet2s128 MBJudgeable
Sum of Sequence ValuesGiven an array, compute the sum over all contiguous subarrays of (max - min) efficiently for up to 300,000 elements.Medium6StackArray+1No attempts yet1s128 MBJudgeable
Oasis ReunionGiven a line of heights, count pairs who can mutually see each other using a monotonic stack while handling equal-height ties correctly.Medium6StackArrayNo attempts yet1s256 MBJudgeable
Doubly Linked ListGiven a sequence of doubly linked list move operations, output the minimum number of operations that reverse them and restore the original order.Medium6Linked listStack+1No attempts yet1s128 MBJudgeable
String CensorshipRepeatedly delete the first then last occurrence of a pattern string from a text until it's absent, and output the final text.Medium6String matchingStack+1No attempts yet1.5s128 MBJudgeable
BracketsCount, modulo 1e9+9, the ways to turn some matching '(' '(' pairs back into '[' ']' so the bracket string becomes valid with at least one square pair.Medium6Dynamic programmingStack+1No attempts yet1s128 MBJudgeable
Magic ParenthesisGiven a bracket string with wildcard characters ']' that each consume one or more open parentheses, determine feasibility and output the lexicographically largest assignment of counts for each wildcard.Medium6GreedyStack+1No attempts yet5s128 MBJudgeable
The SetStack ComputerSimulate a stack machine whose elements are hereditarily finite sets, printing top-of-stack cardinality after each of five set operations.Medium6Hash mapStack+2No attempts yet1s128 MBJudgeable
City GameGiven several grid maps of free and reserved cells, find the largest all-free rectangle in each grid and print its area times three.Medium6StackDynamic programming+1No attempts yet1s128 MBJudgeable
Stupendous ManGiven a sequence where each label 1..N appears twice, decide whether the labels can trace one closed loop of a self-crossing path or not.Medium6StackImplementation+1No attempts yet1s128 MBJudgeable
HTML EditorGiven a valid HTML string and a range, output that substring wrapped with the tags needed to preserve its formatting.Medium6StringStack+1No attempts yet1s128 MBJudgeable
ChemistryParse a chemical formula with nested parentheses and multipliers, then output each element's total atom count in lexicographic order.Medium6StackString+2No attempts yet1s128 MBJudgeable
Removing ParenthesesGiven an expression of single-letter variables with addition and multiplication, remove every pair of parentheses that can go without changing the value, and print the result.Medium6StackString+2No attempts yet1s128 MBJudgeable
XML ValidatorDecide for each input line whether it is valid XML: matching open and close tags, allowed plain text, and proper escape sequences.Medium6StringStack+1No attempts yet1s128 MBJudgeable
ResistorsParse a nested expression of series and parallel resistor connections and output the exact resistance as a reduced fraction.Medium6StringStack+2No attempts yet1s128 MBJudgeable
Binary Search TreeGiven the preorder traversal of a binary search tree, print its postorder traversal.Medium6TreeDivide and conquer+2No attempts yet1s256 MBJudgeable
Time TravelProcess add, pop, and rewind-to-earlier-query operations on a recorded list, printing the last element after each query.Medium6StackTree+2No attempts yet1s128 MBJudgeable
Leaking DikeGiven building heights in a row, water pours over a dike on the left at 1 square meter per minute; find how long until a given building's roof sits 1 meter under water.Medium6ArraySimulation+2No attempts yet1s128 MBJudgeable
Instant ComplexityParse a small nested-loop program, compute its running time as a polynomial in n, and print the collected polynomial from highest degree down.Medium6ImplementationStack+2No attempts yet1s128 MBJudgeable
A Well-Formed ProblemParse a series of XML documents and decide whether each one satisfies six well-formedness rules, reporting the verdict per document.Medium6StringStack+2No attempts yet1s128 MBJudgeable
Largest Rectangle in a HistogramGiven a histogram of unit-width bars with varying heights, find the area of the largest rectangle that fits inside it, processing several test cases until a 0 terminates input.Medium6StackArray+2No attempts yet1s256 MBJudgeable
Bug CatcherFor each code line, repeatedly remove the first occurrence of a given bug string until no occurrence remains, then print the result.Medium6StackString+1No attempts yet1s128 MBJudgeable
ReorganizationGiven each employee's rank in ID order, decide whether a binary hierarchy exists where every non-root has a supervisor with a smaller ID and a better rank.Medium6GreedyTree+2No attempts yet2s512 MBJudgeable
Remove Redundant ParenthesesGiven valid arithmetic expressions over single uppercase variables with + and -, remove every matching parenthesis pair whose removal keeps the expression's value unchanged.Medium6StackString+2No attempts yet1s128 MBJudgeable
BracketsGiven a bracket string, find the maximum length of a regular bracket sequence obtainable as a subsequence.Medium6Dynamic programmingIntervals+1No attempts yet1s128 MBJudgeable
PetrolGiven fuel prices at ordered stations and distances between them, find the minimum fuel cost to travel from A to B with a fixed tank capacity.Medium6GreedyStackNo attempts yet1s128 MBJudgeable
Bracket ExpressionsThe task is to count substrings of a bracket string that are correct bracket sequences.Medium6StackDynamic programmingNo attempts yet1s512 MBJudgeable
Turtle GraphicsSimulate the direction-digit moves, erasing each loop or overlap as it forms, then report the remaining segment count and total length.Medium6SimulationStack+2No attempts yet1s128 MBJudgeable
KTXDecide whether a departure permutation can be reordered into ascending grade order using a direct main line and two LIFO bypass tracks.Medium6StackBacktracking+1No attempts yet1s128 MBJudgeable
Cartesian TreeBuild the Cartesian tree whose inorder follows one key and heap order follows the other, printing parents and children, or NO when impossible.Medium6StackSorting+1No attempts yet2s64 MBJudgeable
Bob's House SiteCount the subrectangles of an N by M elevation grid whose covered cells all have equal height.Medium6StackMatrix+1No attempts yet1s64 MBJudgeable
MarkleftThe program converts each input line with nested markup rules for uppercase, quote escaping, decimal to hex, reversal, and verbatim copying.Medium6StackString+1No attempts yet1s256 MBJudgeable
Red RectanglesCount the subrectangles of an N by M red and blue grid that contain only red cells.Medium6StackDynamic programming+1No attempts yet1s512 MBJudgeable
InterpreterRun small integer programs with arithmetic, comparisons, if/else branches, while loops, and print statements.Medium6SimulationImplementation+2No attempts yet1s256 MBJudgeable
Slon's ExpressionParse a linear expression in x and find the smallest non-negative x with the expression congruent to P modulo M.Medium6Number theoryMath+1No attempts yet1s64 MBJudgeable
Largest Rectangle of OnesFind the area of the largest all-ones subrectangle in each binary matrix given until 0 0.Medium6StackMatrix+1No attempts yet3s512 MBJudgeable
A Scary Part-Time JobGiven daily wages, choose a contiguous range maximizing (length of range) times (minimum wage in that range).Medium6StackGreedyNo attempts yet1s512 MBJudgeable
MarathonGroups at distinct coordinates move right at speed 100/size and merge on contact; simulate until stable and report final sizes left to right.Medium6StackSimulation+2No attempts yet0.2s256 MBJudgeable
Cutting the puzzleGiven the heights of a histogram, find the area of the largest axis-aligned rectangle contained in it.Medium6StackArrayNo attempts yet2s256 MBJudgeable
Flow Graph ComplexityParse a comma-separated flow-graph string of S, B(...), L(...) nodes, count forward and backward edges and nodes, and print |EF| + W*|EB| - |V| + 2 or -1 if malformed.Medium6StringImplementation+2No attempts yet1s512 MBJudgeable
Tree Country Tour GuideGiven the move sequence of a shortest round trip that visits every node of an unknown rooted tree, reconstruct each city's parent.Medium6StackTree+1No attempts yet1s512 MBJudgeable
Building a SpaceshipPartition the ordered parts into contiguous groups, paying for each group the product of its maximum weight and maximum energy; minimize the total cost.Medium6Dynamic programmingArray+2No attempts yet2s512 MBJudgeable
Hyunwook Is the Parenthesis King!!Given a string of parentheses, find the length of the longest contiguous substring that forms a correct parenthesis string.Medium6StackString+2No attempts yet2s512 MBJudgeable
ChainFor each position, repeatedly jump to the first strictly greater element on its right and report the length of that chain.Medium6StackDynamic programming+1No attempts yet2s512 MBJudgeable
Generalized German QuotationGiven a string of << and >> marks, decide whether it forms nested conventional or reversed German quotes and rewrite every mark as an opening [ or closing ], or report that none exists.Medium6StackImplementation+1No attempts yet3s512 MBJudgeable
New GameSimulate a board game where K stacked pieces move in numbered order and reverse, redirect, or merge based on cell color, and report the turn a stack reaches 4 pieces or -1.Medium6SimulationImplementation+2No attempts yet0.5s512 MBJudgeable
One of EachGiven a sequence containing every value 1 to k at least once, find the lexicographically smallest subsequence that includes each value exactly once.Medium6GreedyStack+2No attempts yet2s512 MBJudgeable
Unique CalculatorEvaluate an arithmetic expression by repeatedly reducing the operator at either end with the highest precedence and largest result, following the stated tie-break rules.Medium6ImplementationSimulation+2No attempts yet1s1024 MBJudgeable
Modified HanoiSimulate a modified Tower of Hanoi with a no-repeat-move rule and a fixed move priority order, counting moves until all disks gather on one pole.Medium7SimulationRecursion+2No attempts yet2s128 MBJudgeable
Tilted Square DisplayPlace 45-degree tilted squares along the x-axis one by one without overlap, then find which squares are visible when viewed from directly above.Medium7GeometrySimulation+2No attempts yet2s128 MBJudgeable
Warehouse PolygonGiven pillar positions and heights, compute the minimum area of a roof polygon that covers all pillars while forming a shape without concave water-collecting dips, using a monotonic stack over the skyline.Medium7StackGeometry+1No attempts yet2s128 MBJudgeable
Connecting Black and White PointsPair n black and n white points on a line with non-crossing arcs of chosen height, minimizing total arc length, and output the pairing.Medium7GreedyStack+2No attempts yet1s128 MBJudgeable
Attractive FenceArrange purchased plank heights to match a given up/down pattern while maximizing the sum of absolute differences between adjacent planks.Medium7GreedySorting+1No attempts yet1s128 MBJudgeable
Alien Guitar PerformanceSimulate finger presses and releases on a 6-string guitar to play a melody in order with minimum total finger movements, keeping only pressed frets that could still be the highest useful one.Medium7StackGreedy+1No attempts yet1s256 MBJudgeable
Clearing the BeadsFind the minimum number of beads to insert between colored beads so every bead can eventually be cleared by removing runs of length at least K.Medium7Dynamic programmingStack+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
FenceGiven overlapping rectangular planks forming a skyline, select the minimum subset of planks that reproduces the exact same skyline.Medium7SortingStack+2No attempts yet1s128 MBJudgeable
Interval GroupsGiven a permutation of 1..N arranged on a board, decide if adjacent groups can be merged repeatedly into intervals until one group remains, and output the merge sequence if possible.Medium7GreedyStack+2No attempts yet1s128 MBJudgeable
After the Contest: BalloonsSimulate balloons inflated left to right on a line, each stopping at its max radius or when it touches an earlier balloon, and output the final radii efficiently.Medium7Binary searchGeometry+1No attempts yet1s128 MBJudgeable
SubmarinesMaintain a sequence under adjacent swaps and repeatedly report the maximum in-degree in the 'nearest deeper element behind' functional graph.Medium7StackSegment tree+1No attempts yet3s128 MBJudgeable
Time Limit ExceededParse nested loops with arguments x, y, or integers, compute the Big-O polynomial of basic operations, and print terms sorted by degree.Medium7StackImplementation+2No attempts yet1s128 MBJudgeable
Airplane ParkingGiven N time intervals (arrival, departure), find the largest subset that can be scheduled in a stack, so planes leave in last-in first-out order.Medium7Dynamic programmingIntervals+2No attempts yet1s128 MBJudgeable
Two-Stacks SolitaireGiven a stock pile dealt in order, decide whether the top card can be moved to intermediate pile 1 or 2 or popped to the foundation so all cards end non-decreasing.Medium7Dynamic programmingStack+2No attempts yet1s128 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
BookshelfPartition the books, in order, into shelves of total width at most L to minimize the sum of each shelf's max height.Medium7Dynamic programmingSegment tree+1No 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
ExpressionsGiven a postfix expression, produce another postfix expression that the same algorithm evaluates to the same value when a queue replaces the stack.Medium7StackQueue+2No attempts yet1s128 MBJudgeable
Binary Search Heap ConstructionGiven label/priority pairs, build the unique treap (a binary search tree on labels and a max-heap on priorities) and print it in nested parenthesized form.Medium7TreeStack+2No attempts yet1s128 MBJudgeable
Pyramid Message SchemeGiven a chronological list of message recipients from a sequential tree traversal, reconstruct the tree and compute the time saved by a parallel traversal.Medium7TreeStack+2No attempts yet1s128 MBJudgeable
CaveGiven floor and ceiling heights along a cave, find the maximum total area of settled fuel ponds that stay below the ceiling.Medium7StackGreedy+1No attempts yet3s512 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
ParcelGiven an n by n grid of 0 (arable) and 1 (waste), find the largest all-zero rectangle and print its area. n can be up to 2000.Medium7StackDynamic programming+2No attempts yet3s512 MBJudgeable
TreesGiven a sequence of leaf levels, decide whether it is a valid complete binary tree; if so, output the genealogical and bracket representations.Medium7TreeRecursion+2No attempts yet1s128 MBJudgeable
PosteringGiven adjacent buildings with widths and heights, find the minimum number of non-overlapping rectangles needed to cover the whole skyline shape.Medium7StackGreedyNo attempts yet1s128 MBJudgeable
Railway SidingAssign each arriving car to one of two stack-like sidetracks so all cars leave in increasing order.Medium7StackGreedy+1No attempts yet1s128 MBJudgeable
Farmer's FieldCount placements of a c-by-d or d-by-c rectangle fully inside a field whose every row is one contiguous segment.Medium7Sliding windowStack+2No attempts yet1s128 MBJudgeable
VisibilityGiven a sequence, count pairs whose relationship is in the transitive closure of the direct-visibility relation defined by strictly smaller intervening elements.Medium7StackGraph+2No attempts yet1s128 MBJudgeable
AptekaPay each swapped person by distance times their fee and reach the front with the smallest total cost.Medium7Dynamic programmingGreedy+1No attempts yet1s512 MBJudgeable
Chemicals MonitoringVictor admits the maximum-priority subset of streams that one shared output unit can report in stack order.Medium7Dynamic programmingStack+2No attempts yet4s256 MBJudgeable
Go up the UltrasThe program reads an altitude profile of up to 100000 points and prints the indices of every peak with prominence of at least 150000 centimeters.Medium7StackSegment treeNo attempts yet1s128 MBJudgeable
Sequence MergingRepeatedly replace an adjacent pair with its larger value and pay that value, ordering the merges to leave the smallest total cost.Medium7Divide and conquerStack+1No attempts yet1s128 MBJudgeable
Circle RegionsCount how many regions N circles with centers on the x-axis and no crossings cut the plane into.Medium7StackSorting+2No attempts yet1s256 MBJudgeable
CATSGiven X, L and N, simulate the buggy two-stack counter program with global bit flips and output the number it prints.Medium7SimulationStack+2No attempts yet2s512 MBJudgeable