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 results514 problems
TitleLevelTopicsSolvedTime limitMemory limitJudge
Aku NegarakuFor each N and M, simulate Josephus elimination around a circle and report the last remaining trainee's number.Medium4SimulationArray+1No attempts yet3s512 MBJudgeable
Counting Langford SequencesCount Langford sequences of length 2n where the numbers at positions x and y are equal, for n up to 12.Medium4BacktrackingRecursion+2No attempts yet2s512 MBJudgeable
Collecting EnergyGiven a row of N weighted beads (N up to 10), remove interior beads one at a time, scoring the product of the neighbors left and right, and maximize the total score.Medium4Dynamic programmingRecursion+1No attempts yet1s512 MBJudgeable
I'm Sick of Fibonacci~Given n, count the total number of calls made by the naive recursive Fibonacci function, modulo 1,000,000,007.Medium4Dynamic programmingRecursion+2No attempts yet1s512 MBJudgeable
Road ConstructionGiven a tree with n countries and weighted edges, sum over all edges of weight times the absolute difference in size of the two components the edge splits the tree into.Medium4TreeDFS+2No attempts yet2s512 MBJudgeable
Jerry and Tom 2Given N and values a1..aN, compute 1 minus the continued fraction 1/(a1 + 1/(a2 + ... + 1/aN)) as a reduced fraction P/Q.Medium4MathNumber theory+2No attempts yet1s256 MBJudgeable
Gugu the RaccoonGiven a weighted tree rooted at node 1, find the maximum distance from node 1 to any other node.Medium4TreeDFS+2No attempts yet1s1024 MBJudgeable
Number of PapersGiven an N x N grid of -1, 0, 1 values, recursively split non-uniform blocks into 9 equal sub-squares and count how many final uniform blocks hold each value.Medium5Divide and conquerRecursion+2No attempts yet2s256 MBJudgeable
Removing ParenthesesGiven an arithmetic expression with letters and +,-,*,/,() parse it and print an equivalent expression using the fewest parentheses, applying sign/operator flips when parentheses are removed.Medium5RecursionString+1No attempts yet2s128 MBJudgeable
Sequence ReductionDecide if repeatedly merging adjacent elements as A[i]-A[i+1] can reduce the sequence to a single target value T.Medium5Dynamic programmingRecursionNo attempts yet2s128 MBJudgeable
Tree Height and WidthGiven a binary tree's parent-child structure, place nodes on a grid by binary tree layout rules and find the level with the maximum column width, breaking ties by smallest level.Medium5TreeBFS+1No attempts yet2s128 MBJudgeable
Recover Tree PreorderGiven a tree's inorder and postorder sequences, reconstruct the tree and output its preorder traversal.Medium5TreeRecursion+1No attempts yet5s128 MBJudgeable
SequenceFind the K-th lexicographically smallest non-decreasing sequence of N positive integers summing to M.Medium5BacktrackingCombinatorics+1No attempts yet2s128 MBJudgeable
Star Printing - 10Recursively draw a Sierpinski-like N x N star pattern where N is a power of 3, replicating the base 3x3 block with blank centers at every scale.Medium5RecursionMatrix+1No attempts yet1s256 MBJudgeable
A Margarita Today?Count subsets of up to 30 prices whose sum is within budget D and whose leftover money cannot afford any unchosen item.Medium5Brute forceRecursion+1No attempts yet1s128 MBJudgeable
SudokuFill the five empty cells (marked 0) in a 9x9 Sudoku grid so every row, column, and 3x3 box contains the digits 1 through 9 exactly once.Medium5BacktrackingImplementation+2No attempts yet1s128 MBJudgeable
Folding GameFor each fold sequence on a rectangle, count how many paper layers sit under a given point.Medium5SimulationImplementation+2No attempts yet1s128 MBJudgeable
Flipping ColorsRepeatedly split each rectangle in fixed ratios h:v and flip the colors of the upper-right and lower-left parts; report the color reached by each query point.Medium5RecursionDivide and conquer+2No attempts yet1s128 MBJudgeable
Genealogical ResearchProcess birth and death records, then answer ancestor and descendant queries by printing the family tree recursively with dates.Medium5RecursionTree+2No attempts yet1s128 MBJudgeable
FrenemiesFor each dataset, sum the signed scores of all simple paths without neutral links between a given person and every other person.Medium5DFSGraph+2No attempts yet1s128 MBJudgeable
Sum It UpGiven a target and up to 12 numbers, list every distinct subset sum equal to the target, sorted in decreasing lexicographic order.Medium5BacktrackingSorting+2No attempts yet1s128 MBJudgeable
The End of the WorldGiven a valid intermediate state of the Towers of Hanoi, compute how many more moves remain in the optimal solution.Medium5RecursionDivide and conquer+2No attempts yet1s128 MBJudgeable
Normal FormEvaluate a fully parenthesized AND/OR tree where odd levels are AND and even levels are OR, for several long test cases.Medium5TreeImplementation+2No attempts yet1s128 MBJudgeable
Introduction to Digital CircuitsParse three-valued logic expressions over P, Q, R and count how many of the 27 assignments make the expression evaluate to 2.Medium5RecursionImplementation+2No attempts yet1s128 MBJudgeable
lsGiven a wildcard pattern where * matches any run of characters, print the input file names that match it, keeping input order.Medium5Dynamic programmingString+2No attempts yet1s128 MBJudgeable
Royal SuccessionGiven parent pairs for N people, compute each claimant's inherited fraction of the founder's blood and print the claimant with the largest fraction.Medium5GraphDFS+2No attempts yet1s128 MBJudgeable
Listing Square Arrangements in Lexicographic OrderList every partition of n whose parts are non-increasing, and print the sequences in decreasing lexicographic order.Medium5BacktrackingRecursion+2No attempts yet1s128 MBJudgeable
SymmetryCount the squares a recursive center-splitting process marks on an N by M grid, where each step splits an odd-by-odd field into four half-sized subfields.Medium5RecursionMath+2No attempts yet1s128 MBJudgeable
Best ParenthesisGiven a balanced parenthesis string encoded as 0/1 values, compute its recursively defined score modulo 12345678910.Medium5StackRecursion+2No attempts yet1s256 MBJudgeable
Skewed SortingApply a recursive swap procedure on 2^N cows, comparing equal-length halves as base-2^N numbers, and report total distance moved plus final order.Medium5Divide and conquerRecursion+2No attempts yet1s128 MBJudgeable
The Big DanceRepeatedly split the interval 1..N at the middle (front group gets the extra when odd), pairing cows when a group has exactly two, and add each pair's product to a running sum.Medium5Divide and conquerRecursion+2No attempts yet1s128 MBJudgeable
Treasure CaveGiven a binary branching from passage 1, find the list of passages on the unique path from the entrance to passage T and its length.Medium5TreeDFS+2No attempts yet1s128 MBJudgeable
Bit MapsConvert a rectangular bitmap between raw 0/1 array form and its recursive quadrant decomposition, honoring the split rules for odd dimensions.Medium5Divide and conquerRecursion+2No attempts yet1s128 MBJudgeable
SlurpysGiven up to 10 short strings, decide whether each one is a Slurpy, meaning a Slimp followed by a Slump under the recursive grammar in the statement.Medium5RecursionString+2No attempts yet1s128 MBJudgeable
In DangerGiven n people in a circle where every second person is eliminated starting from person 1, report the final surviving position; n arrives encoded as xyez.Medium5MathRecursion+2No attempts yet1s128 MBJudgeable
The Sierpinski FractalDraw the outline of a depth-n Sierpinski triangle in ASCII, 2^n rows tall, with no trailing spaces and blank lines between the test cases.Medium5Divide and conquerRecursion+2No attempts yet1s128 MBJudgeable
Decode the TreeGiven a Prüfer code, rebuild the labeled tree on n vertices and print it as a canonical rooted word with children sorted by number.Medium5TreeHeap+2No attempts yet1s128 MBJudgeable
Quad TreeDecode a quad tree string into an n by n black and white image, then print each row as XBM hexadecimal bytes.Medium5RecursionDivide and conquer+2No attempts yet1s128 MBJudgeable
Solving Linear EquationsParse each linear equation written in a recursive grammar with parentheses and multiplication, then report no, infinite, or the unique solution rounded to six decimals.Medium5MathRecursion+2No attempts yet1s128 MBJudgeable
Alice Through the Looking GlassGiven a magnification level and a cell coordinate, decide whether that cell of the 5^m by 5^m self-similar grid is filled or empty.Medium5RecursionDivide and conquer+1No attempts yet2s512 MBJudgeable
Twenty-fourFor each hand of four cards, find the largest integer value at most 24 reachable by an expression that uses all four values with +, -, *, / and only exact division.Medium5Brute forceRecursion+2No attempts yet1s128 MBJudgeable
BananasDecide for each word whether it fits the recursive grammar of a monkey language, where words wrap other words in N and in B...S.Medium5StringRecursion+2No attempts yet1s128 MBJudgeable
Divided FractalsPrint a rectangle of an iterated square fractal, with rows numbered bottom to top and cells joined by spaces.Medium5RecursionImplementation+2No attempts yet1s128 MBJudgeable
Pattern GeneratorFor each (n, k) pair, print all n-bit strings with exactly k ones in decreasing numeric order, separated by blank lines.Medium5BacktrackingRecursion+2No attempts yet1s128 MBJudgeable
Tree CuttingOn a tree of N nodes, print every node whose removal leaves each connected piece with at most floor(N/2) nodes, or NONE.Medium5TreeDFS+2No attempts yet1s128 MBJudgeable
Reconstructing Binary TreesGiven the pre-order and in-order traversals of a binary tree with distinct labels, print its post-order traversal or report that no tree matches.Medium5TreeRecursion+2No attempts yet1s128 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
SizeofRead a word size and a nested struct declaration and compute its storage size with word alignment.Medium5RecursionImplementation+1No attempts yet1s128 MBJudgeable
Make the target from four numbersDecide whether the first four integers can form the fifth using each exactly once with +, -, *, / and parentheses.Medium5Brute forceBacktracking+1No attempts yet1s128 MBJudgeable
One Move from Towers of HanoiGiven n disks and an index k, report the disk and the source and destination posts of the kth move in the classic recursive Hanoi solution.Medium5RecursionBit manipulation+1No attempts yet3s128 MBJudgeable
All SquaresGiven starting size k, count the nested corner squares whose border or interior holds the query point.Medium5RecursionGeometryNo attempts yet1s128 MBJudgeable
Blue Gene, Jr.Simulate the recursive mutation rules on each short alphanumeric code and print the stabilized code.Medium5RecursionSimulation+1No attempts yet1s128 MBJudgeable
The Binary Search Efficiency DoubterGiven a list length n, compute the total number of binary search loop iterations spent finding every element.Medium5MathBinary search+1No attempts yet1s256 MBJudgeable
Formula EquivalenceDecide whether two Boolean formulas with AND, OR, and NOT over at most 16 variables agree on every truth assignment.Medium5Brute forceRecursionNo attempts yet1s256 MBJudgeable
Googol String (Large)Answer the Kth character of a recursively defined binary string for each query with K up to 10^18.Medium5RecursionBit manipulationNo attempts yet5s512 MBJudgeable
Broken Calculator (Small)Split X into factors typed with working digits only, minimizing the total of digit, multiply, and equals presses.Medium5Dynamic programmingRecursion+1No attempts yet5s512 MBJudgeable
Decision Tree (Large)Parse a nested decision tree with optional feature names, then multiply node weights along the path chosen by each animal's features.Medium5StringRecursion+2No attempts yet5s512 MBJudgeable
A and B 2Given two strings of A and B, decide whether repeatedly appending A or appending B then reversing can turn S into T.Medium5StringGreedy+2No attempts yet2s512 MBJudgeable
Palindromic substringsCount length-N uppercase strings whose length-M substrings include at least K palindromes.Medium5Brute forceString+2No attempts yet2s512 MBJudgeable
Movement 3Decide whether (x, y) is reachable by moving 3^k right or up on each step k, starting at the origin.Medium5MathBit manipulation+1No attempts yet2s512 MBJudgeable
Equal leaf distancesRaise edge weights in a weighted perfect binary tree so every root-to-leaf path has equal length, minimizing the total weight.Medium5TreeGreedy+2No attempts yet1s512 MBJudgeable
ResignationGiven each day's consultation length and payment, pick a non-overlapping set of jobs that all finish before day N+1 to maximize total payment.Medium5Dynamic programmingBrute force+1No attempts yet2s512 MBJudgeable
Reincarnated as a Slime Researcher (Easy)Given a starting integer K, repeatedly factor it into two factors at least 2, minimizing the maximum number of splits along any root to leaf path.Medium5GreedyNumber theory+2No attempts yet0.5s512 MBJudgeable
SlurpyDecide whether each uppercase string is a Slurpy, meaning a Slimp immediately followed by a Slump, where both are defined by recursive grammar rules.Medium5RecursionString+2No attempts yet2s512 MBJudgeable
TilingCount the ways to tile a 3 by W rectangle with 2 by 1 dominoes, printing the result modulo 1e9+7.Medium5Dynamic programmingCombinatorics+2No attempts yet2s512 MBJudgeable
Sum of a geometric sequenceAdd the first n terms of a geometric sequence with first term a and ratio r, then print the sum modulo mod.Medium5Divide and conquerMath+1No attempts yet0.5s128 MBJudgeable
Engineering CalculatorEvaluate an integer arithmetic expression with precedence, right-associative exponentiation and square root, and truncation toward zero for incomplete roots and divisions.Medium5RecursionMath+2No attempts yet1s256 MBJudgeable
BlogGiven a string of R, G, and B, find the minimum number of contiguous same-color paint operations needed to build it.Medium5Dynamic programmingString+2No attempts yet1s256 MBJudgeable
Level HamburgerA level-N burger is defined recursively from buns and patties; count how many patties lie in the bottom X layers.Medium5RecursionDivide and conquer+2No attempts yet0.5s512 MBJudgeable
What Does UNIST Stand For?Count ways to pick a prefix of each of N words so the concatenation spells UNIST, modulo 1e9+7.Medium5Dynamic programmingString+2No attempts yet1s512 MBJudgeable
Fractal PlanePrint a rectangular window of the grid at time s, where each step splits every cell into N x N and blacks out a centered K x K block.Medium6Divide and conquerRecursion+2No attempts yet2s128 MBJudgeable
Random Number GeneratorGiven a linear congruential generator with huge parameters up to 10^18, compute the n-th term modulo m and then modulo g using fast exponentiation.Medium6MathRecursion+2No attempts yet2s128 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
Infinite Sequence 2Compute A_N for a recursively defined sequence using nested floor divisions, requiring memoized recursion over a bounded set of distinct arguments.Medium6RecursionMath+2No attempts yet10s512 MBJudgeable
Sum of Largest Power-of-Two DivisorsGiven A and B up to 10^15, compute the sum over that range of the largest power-of-two divisor of each integer.Medium6MathNumber theory+2No attempts yet2s128 MBJudgeable
Prefix Reversal 3Given a string, for each prefix length from 1 to N in order you may choose to reverse that prefix, and you must output the lexicographically smallest string achievable after all choices.Medium6StringGreedy+2No attempts yet2s128 MBJudgeable
Tree EncodingGiven N and an index, find the k-th lexicographically smallest preorder traversal string among all binary search trees built from the first N letters, using Catalan number counting.Medium6CombinatoricsMath+2No attempts yet2s128 MBJudgeable
Substitution Sequence Range CountsCount occurrences of 1, 2, 3 in a fixed interval of a sequence generated by simultaneous ternary substitution after N steps, without building the whole sequence.Medium6RecursionDivide and conquer+2No attempts yet2s128 MBJudgeable
Fiibonacci TreeGiven preorder indices of two nodes in a recursively built Fibonacci binary tree, compute the shortest L/R/U path between them without ever materializing the tree.Medium6TreeRecursion+2No attempts yet2s128 MBJudgeable
XYZ StringGiven a self-similar X/Y/Z rewriting sequence, answer queries about the stage N string's length, its k-th character, or the count of a given character without building the full string.Medium6RecursionDivide and conquer+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
PibonacciCompute a Fibonacci-like sequence defined with the irrational constant pi as a recursive step and output it modulo 10^18.Medium6Dynamic programmingRecursion+1No attempts yet2s128 MBJudgeable
Paper FoldingGiven a crease pattern of length 2^N-1, decide if it could arise from repeatedly folding the right half of a strip onto the left half.Medium6Divide and conquerRecursion+2No attempts yet2s128 MBJudgeable
Partitioning for Fun and ProfitGiven m, n and k, output the k-th lexicographically smallest partition of m into n non-decreasing positive parts.Medium6CombinatoricsDynamic programming+2No attempts yet2s128 MBJudgeable
Logical ExpressionsParse a custom logical expression grammar with user-defined unary and binary operator truth tables, then evaluate it to true, false, or unknown given partial variable assignments.Medium6RecursionString+2No attempts yet1s128 MBJudgeable
Image CompressionBuild the quadtree of an image padded to the next power-of-two square, then count total nodes and the minimum nodes after sharing identical non-leaf subtrees.Medium6TreeRecursion+2No attempts yet2s128 MBJudgeable
Golomb SequenceGiven n up to 2 billion, compute the n-th term of the self-describing Golomb sequence efficiently.Medium6MathRecursion+1No attempts yet2s128 MBJudgeable
Star Printing - 11Recursively build and print a Sierpinski-like star triangle of height N=3·2^k using the fractal rule of stacking scaled copies with exact spacing.Medium6RecursionImplementation+1No attempts yet1s256 MBJudgeable
Recursive Palindrome PartitionsCount recursive palindrome partitions of N, where a partition is valid if it is a palindrome and both halves are recursively valid.Medium6Dynamic programmingRecursion+2No attempts yet1s128 MBJudgeable
Hanging MonkeysParse a nested bracket string representing a binary vine structure and compute the minimum monkeys needed so every split has equal counts on both sides.Medium6RecursionString+2No attempts yet1s128 MBJudgeable
Complete Binary TreeFill a complete binary tree of level N with numbers 1 to 2^N-1 so each internal node's left/right subtree sums differ by exactly 2^D, then output preorder.Medium6RecursionTree+2No attempts yet1s128 MBJudgeable
Beautiful NamesCount the number of orderings of N distinct strings such that all strings sharing a common prefix always form a contiguous block, modulo 1e9+7.Medium6TrieCombinatorics+1No attempts yet1s512 MBJudgeable
Company RestructuringGiven a rooted tree where reporting edges may only be rewired within original parent-child-sibling triples, output a new tree with at most 2 children per node and at most one higher-IQ child than its manager.Medium6TreeGreedy+1No attempts yet1s128 MBJudgeable
Football RankingRank football teams by points with a recursive mini-league tiebreak among tied teams, falling back to goal difference, goals scored, wins, then team number.Medium6SimulationSorting+2No attempts yet1s128 MBJudgeable
Moore MachineParse a series-parallel Moore machine expression and determine the unique erased output symbol that matches an observed string, or report ambiguity or impossibility.Medium6Dynamic programmingString+2No attempts yet1s128 MBJudgeable
MinistryParse a nested ternary-tree encoding of an organization and, using tree canonicalization/hashing, count structurally distinct subtrees grouped by depth.Medium6TreeRecursion+1No attempts yet2s128 MBJudgeable
FractalGiven a recursively self-similar fractal built from a base polyline, find the point at a given fraction of its total arc length after d recursive refinements.Medium6RecursionGeometry+1No attempts yet1s128 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
FirefightersDetermine if question-mark operators in an arithmetic expression with brackets can be replaced by +,-,*,/ to reach a given target value under integer truncating division.Medium6Brute forceRecursion+1No attempts yet1s128 MBJudgeable
CountdownFind the closest achievable value to a target by combining six given numbers with the four operations, keeping intermediate results positive integers.Medium6Brute forceRecursion+1No attempts yet1s128 MBJudgeable