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
The nth Fibonacci NumberGiven n up to 20, compute the nth Fibonacci number defined from 0 and 1.Easy1Dynamic programmingRecursionNo attempts yet1s256 MBJudgeable
Born in 1998, but 2541 in Thailand?!Given a Buddhist calendar year between 1000 and 3000, print the corresponding Gregorian year by subtracting 543.Easy1MathImplementation+2No attempts yet1s1024 MBJudgeable
Cantor SetFor each N, print a line of 3^N characters following the Cantor set rule: each third-level block of size 3^k has its middle third blanked, dashes elsewhere.Easy2RecursionImplementation+2No attempts yet1s128 MBJudgeable
Constrained PermutationsCount permutations of 1..n (n at most 9) that satisfy given ordering constraints x before y.Easy2Brute forceCombinatorics+2No attempts yet1s128 MBJudgeable
Huffman TreeGiven Z characters and arity N, decode the stored digit string into the per-character encoding.Easy2TreeString+1No attempts yet3s128 MBJudgeable
ICPC CalculatorEvaluate a dot-indented prefix expression where + sums its operands and * multiplies them.Easy2RecursionTree+1No attempts yet1s256 MBJudgeable
Pascal's TriangleGiven n and k with 1 <= k <= n <= 30, print the k-th entry of row n in Pascal's triangle, equal to C(n-1, k-1).Easy2MathCombinatorics+2No attempts yet1s256 MBJudgeable
What Is a Recursive Function?Given N, print the chatbot message 'What is a recursive function?' repeated with nested quotation marks for N levels of recursion.Easy2ImplementationString+1No attempts yet1s256 MBJudgeable
ZGiven N and coordinates (r,c) in a 2^N x 2^N grid, compute the visit order index of that cell under recursive Z-order (Morton order) traversal.Easy3Divide and conquerRecursion+1No attempts yet0.5s512 MBJudgeable
Largest Lucky NumberGiven N up to 1,000,000, find the largest number no greater than N whose digits are only 4s and 7s.Easy3RecursionBrute force+1No attempts yet2s256 MBJudgeable
Count Numbers Made Only of 4 and 7Count integers between A and B (up to 1e9) whose digits are all 4s and 7s.Easy3Brute forceCombinatorics+2No attempts yet2s128 MBJudgeable
Modular ExponentiationCompute A raised to the power B modulo C efficiently using fast modular exponentiation.Easy3MathNumber theory+1No attempts yet0.5s128 MBJudgeable
Tower of HanoiPrint the minimum move count for Tower of Hanoi with N disks, using big-integer count for N up to 100 and the explicit move sequence when N is at most 20.Easy3RecursionMath+1No attempts yet6s128 MBJudgeable
Tree TraversalBuild a binary tree from parent-child input and print its preorder, inorder, and postorder traversals.Easy3TreeDFS+1No attempts yet2s128 MBJudgeable
Making Colored PaperRecursively quadtree-split an N×N grid of 0/1 cells into uniform-color squares and count the resulting white and blue pieces.Easy3RecursionDivide and conquer+1No attempts yet1s128 MBJudgeable
Apartment ResidentsCompute the resident count in room n on floor k, defined by repeated prefix sums starting from room i having i residents on floor 0.Easy3Dynamic programmingMath+1No attempts yet0.5s128 MBJudgeable
Fibonacci NumberGiven n, print the n-th Fibonacci number, where the sequence starts 1, 1 and each later term is the sum of the previous two.Easy3Dynamic programmingMath+2No attempts yet1s128 MBJudgeable
SmeechParse a prefix Smeech expression with probabilistic plus or minus operators and compute its expected value to two decimals.Easy3RecursionMath+2No attempts yet1s128 MBJudgeable
Elias Omega CodingFor each positive integer until a terminating 0, output its Elias omega code, built by recursively prepending the code of the bit length.Easy3Bit manipulationRecursion+2No attempts yet1s128 MBJudgeable
The Leisurely StrollGiven a rooted tree of choice-nodes where leaf edges lead to pastures, find the maximum number of edges on any root-to-pasture path.Easy3TreeDFS+2No attempts yet1s128 MBJudgeable
Going to the MoviesGiven a truck capacity C and up to 16 cow weights, pick a subset whose total weight is as large as possible without exceeding C.Easy3Brute forceBacktracking+2No attempts yet1s128 MBJudgeable
Help the problem setterFor each test case, read a binary search tree on labels 1..n and print each node's frequency, computed bottom-up as 1 plus the sum of the frequencies of all its proper descendants.Easy3TreeDFS+2No attempts yet1s128 MBJudgeable
Genetic CodePrint the first n characters of the infinite square-free sequence generated by the substitution N→NOP, O→NP, P→O.Easy3StringRecursionNo attempts yet1s128 MBJudgeable
Stuttering StringsFor each input case, the program prints every length-n string over * and ! whose runs stay within the given limits, in lexicographic order with * first.Easy3BacktrackingRecursion+1No attempts yet1s128 MBJudgeable
Function run funCompute the recursive function w(a, b, c) with memoization for each query line until -1 -1 -1.Easy3Dynamic programmingRecursionNo attempts yet1s128 MBJudgeable
Even More DicePrint every nondecreasing roll of n m-sided dice that sums to s in lexicographic order for each test case.Easy3BacktrackingRecursionNo attempts yet5s512 MBJudgeable
Bus 3000Given k stops where half the riders plus half a rider get off each time until the bus is empty, find the starting passenger count.Easy3MathRecursionNo attempts yet1s128 MBJudgeable
Candy FactoryEach parent in a heap-ordered binary tree makes as many candies as the smaller child count, and the total subtracts consumed ingredients from all made candies.Easy3TreeRecursion+1No attempts yet1s128 MBJudgeable
Quadtree Image CompressionCount the bits produced by recursively splitting an L by L binary image into quadrants until each block is uniform.Easy3Divide and conquerRecursion+1No attempts yet2s1024 MBJudgeable
Complete Binary TreeReconstruct each level of a complete binary tree from its inorder visit order.Easy3TreeRecursionNo attempts yet1s128 MBJudgeable
All PermutationsPrint every permutation of the numbers 1 to N in lexicographic order, one per line.Easy3BacktrackingRecursionNo attempts yet1s256 MBJudgeable
Printing Stars - 19Print the N-level nested square star figure that the sample cases define.Easy3RecursionImplementationNo attempts yet1s256 MBJudgeable
Bell RingingPrint all permutations of 1 to n in the recursive insertion order where bell n sweeps each row left to right or right to left.Easy3RecursionImplementationNo attempts yet2s256 MBJudgeable
Tower of Hanoi move sequencePrint the minimal sequence of moves that transfers N disks from rod 1 to rod 3 under the smaller-on-larger rule.Easy3RecursionImplementationNo attempts yet1s256 MBJudgeable
Googol String (Small)Build the recursive 0/1 string defined by S with a middle 0 plus a switched reversal, then answer the Kth character for each test case.Easy3RecursionSimulationNo attempts yet5s512 MBJudgeable
TriangleRecursively subdivide a triangle into three corner triangles N-1 times and print the resulting ASCII fractal.Easy3Divide and conquerRecursion+1No attempts yet1s64 MBJudgeable
String PermutationPrint every permutation of a short string of distinct characters, in the order given by the original character positions.Easy3BacktrackingRecursion+1No attempts yet5s512 MBJudgeable
N and M (1)Print every length-M sequence of distinct numbers chosen from 1 to N, in increasing lexicographic order.Easy3BacktrackingRecursionNo attempts yet1s512 MBJudgeable
N and M (2)Print all ascending sequences of M distinct numbers chosen from 1 to N, in lexicographic order.Easy3BacktrackingRecursion+1No attempts yet1s512 MBJudgeable
N and M (3)Print every length-M sequence from 1 to N in lexicographic order, allowing repeats.Easy3BacktrackingRecursion+2No attempts yet1s512 MBJudgeable
N and M (4)Print all non-decreasing sequences of length M chosen from 1 to N, each exactly once, in lexicographic order.Easy3BacktrackingRecursionNo attempts yet1s512 MBJudgeable
Length M sequences from N numbersGiven N distinct numbers and an M, print every length-M permutation of the numbers in lexicographic order without repeats.Easy3BacktrackingRecursion+2No attempts yet1s512 MBJudgeable
N and M (6)Given N distinct natural numbers and M, print every ascending M-element subsequence in lexicographic order without repeats.Easy3BacktrackingSorting+2No attempts yet1s512 MBJudgeable
N and M (10)Given N numbers and an M, print every non-decreasing length-M selection of the numbers in lexicographic order without duplicates.Easy3BacktrackingSorting+2No attempts yet1s512 MBJudgeable
Virus OutbreakRead hour values until -1 and print the Fibonacci number a(X) for each in the format 'Hour X: Y cow(s) affected'.Easy3MathDynamic programming+2No attempts yet2s512 MBJudgeable
Binary Search TreeInsert a sequence of integers into a BST and output the depth of each inserted node.Easy3TreeRecursion+1No attempts yet2s512 MBJudgeable
Season of ReadingReplace WHO, WHERE, and WHAT in each sentence with the given resolving elements, expanding nested references.Easy3StringRecursion+1No attempts yet1s512 MBJudgeable
Alpha Tic-Tac-ToeGiven a 3x3 tic-tac-toe board with X to move or O to move, find whether the side to move can force a win, a draw, or only a loss under perfect play.Easy3Game theoryRecursion+1No attempts yet1s256 MBJudgeable
Total Number of CountsGiven N bills and bundle size M, repeatedly count items and group them into bundles of M until no bundle can form, then print the total number of counts.Easy3MathSimulation+2No attempts yet1s512 MBJudgeable
Sam-sam NumberDecide whether N can be written as a sum of distinct powers of 3, using each power at most once.Easy3MathImplementation+2No attempts yet1s256 MBJudgeable
Thue-Morse StringFind the character at position k in the Thue-Morse sequence, where k can be as large as 10^18.Easy3Bit manipulationMath+1No attempts yet1s256 MBJudgeable
Endless StringStarting from a string A, repeatedly replace every $ in S with the previous result, then print characters from position min to max after N runs.Medium4StringRecursion+2No attempts yet2s128 MBJudgeable
Infinite SequenceCompute the N-th term of a sequence where A_i equals A at floor(i/P) plus A at floor(i/Q), using memoized recursion for huge N.Medium4RecursionDynamic programming+2No attempts yet2s128 MBJudgeable
Decompressed String LengthCompute the total length of a string after fully expanding nested K(Q) compression patterns, where K is a single digit repeat count.Medium4StackString+1No attempts yet2s128 MBJudgeable
Quad Tree CompressionGiven an N x N binary grid, recursively quadrant-compress it into a string using uniform-region shortcuts and parenthesized quadrant order.Medium4Divide and conquerRecursion+1No attempts yet2s128 MBJudgeable
Chemical Formula MassParse a chemical formula with nested parentheses and digit multipliers to compute the total atomic mass using H=1, C=12, O=16.Medium4StackString+1No attempts yet2s128 MBJudgeable
Bracket ValueParse a bracket string with two bracket types and compute its defined nested value, or output 0 if it is invalid.Medium4StackString+1No attempts yet1s128 MBJudgeable
Molecular MassParse a nested chemical formula with parentheses and repeat counts, then compute the total molecular mass from atomic weights.Medium4StackRecursion+1No attempts yet1s128 MBJudgeable
CalculatorParse and evaluate fully parenthesized arithmetic expressions with big integers up to 90 digits, printing Error on overflow, negative results, or division by zero.Medium4StringMath+2No attempts yet1s128 MBJudgeable
Guess the NumbersDetermine whether some permutation of up to 5 given values assigned to the unknowns in a fully parenthesized arithmetic expression makes it evaluate to a target result.Medium4Brute forceRecursion+1No attempts yet1s128 MBJudgeable
Molecular FormulaParse a nested molecular formula with repetition counts and atomic weight lookups to compute total molecular weight, or report UNKNOWN.Medium4RecursionString+1No attempts yet3s128 MBJudgeable
TreeGiven the preorder and inorder traversals of a binary tree, reconstruct the tree and print its postorder traversal.Medium4TreeRecursion+1No attempts yet1s192 MBJudgeable
TautologyGiven propositional formulas in Polish notation, decide for each whether it is a tautology by parsing and evaluating it over every truth assignment.Medium4StringRecursion+2No attempts yet1s128 MBJudgeable
A Smart Brain is a Tasty BrainParse each of up to 10000 Boolean expressions, evaluate it, and report whether the brain's given answer matches.Medium4StringStack+2No attempts yet1s128 MBJudgeable
Symbolic Logic MechanizationParse a prefix logic formula, report the first syntax error left to right, then classify it as a tautology, contradiction, or contingent.Medium4StringRecursion+2No attempts yet1s128 MBJudgeable
Image CompressionCompress a binary square bitmap with a quadtree and a majority threshold, then output the image the encoding reconstructs.Medium4Divide and conquerRecursion+2No attempts yet1s128 MBJudgeable
Set-Theoretic Number NotationParse two numbers given as von Neumann ordinal sets, add their values, and print the sum in the same nested-brace notation.Medium4StringRecursion+1No attempts yet1s128 MBJudgeable
Musical ChairsGiven N children in a circle and a step D, repeatedly remove the D-th child counting around the circle; report the last child left plus N and D.Medium4MathSimulation+2No attempts yet1s128 MBJudgeable
Flatten the ExpressionParse a recursively repeated bracketed expression and print its flattened string without spaces.Medium4StringRecursion+1No attempts yet1s128 MBJudgeable
Bale ShareAssign N bales (N up to 20) to three barns so the largest barn total is as small as possible, and print that smallest possible largest total.Medium4Brute forceRecursion+2No attempts yet1s128 MBJudgeable
Cow PinballGiven a triangle of nail scores with R rows, find the maximum sum along a path from the top nail down to the last row, moving to one of the two adjacent nails below each step.Medium4Dynamic programmingArray+2No attempts yet1s128 MBJudgeable
Strange Towers of HanoiCompute the minimum number of moves to transfer n disks (n at most 12) from tower A to tower D using four towers.Medium4Dynamic programmingRecursion+2No attempts yet1s128 MBJudgeable
Roads Around the FarmGiven N cows and a difference K, a group of size s splits into two nonempty groups differing by K when possible; count the final grazing groups.Medium4RecursionMath+2No attempts yet1s128 MBJudgeable
The Eating PuzzleGiven up to 21 bucket sizes and a calorie limit, choose a subset with the largest sum that does not exceed the limit.Medium4Brute forceBit manipulation+2No attempts yet1s128 MBJudgeable
The Sultan's SuccessorsFor each 8x8 board, place 8 non-attacking queens to maximize the sum of the numbers on the occupied squares.Medium4BacktrackingRecursion+2No attempts yet1s128 MBJudgeable
Quad TreeParse an XBM hex bitmap, then recursively encode it as a quad tree: uniform squares become B or W, mixed ones become Q followed by four sub-squares.Medium4Divide and conquerRecursion+2No attempts yet1s128 MBJudgeable
Tree RecoveryGiven a binary tree's preorder and inorder traversal strings, print its postorder traversal. Process runs until end of file.Medium4TreeRecursion+1No attempts yet1s128 MBJudgeable
LottoFor each set of k numbers in ascending order, print all 6-element subsets in lexicographic order, separated by blank lines.Medium4BacktrackingRecursion+1No attempts yet1s128 MBJudgeable
Matrix Chain MultiplicationGiven matrices with dimensions and fully parenthesized products, report the elementary multiplication count or an error if dimensions mismatch.Medium4StackRecursion+1No attempts yet1s128 MBJudgeable
From Prefix to PostfixTranslate each prefix arithmetic expression over + and - into its equivalent postfix form, stopping at the terminating 0.Medium4StackTree+2No attempts yet1s128 MBJudgeable
Double Knockout CompetitionSimulate a double-elimination tournament round by round and print the number of undefeated, one-loss, and eliminated teams after each round.Medium4SimulationMath+2No attempts yet1s128 MBJudgeable
BalanceCount the orders and pan choices for placing n distinct weights so the left pan is never heavier than the right at any step.Medium4Brute forceBacktracking+2No attempts yet2s128 MBJudgeable
DyzioParse a 0/1 description of recursive halving cuts and output the cut count at which the first shortest piece appears.Medium4TreeDFS+2No attempts yet1s128 MBJudgeable
Recursive Pattern (Szlaczek)Given a starting sequence that is repeatedly extended by appending its own reversal, report the value at position M.Medium4RecursionArray+1No attempts yet1s128 MBJudgeable
Quad TreesBuild the quadtree partition of each binary image and print its level-order bitstream as uppercase hex without leading zeros.Medium4Divide and conquerRecursion+2No attempts yet1s128 MBJudgeable
Single Digit AdderEvaluate each line as an arithmetic expression of single digits with plus, minus, and parentheses.Medium4StackRecursionNo attempts yet1s128 MBJudgeable
TicketsPrint the K-th n-bit string in reflective Gray code order for the given n and K.Medium4Bit manipulationRecursionNo attempts yet1s64 MBJudgeable
Uncompressing Compressed WordsExpand each nested compressed word by concatenating its parts and repeating the group n times.Medium4RecursionStack+1No attempts yet1s256 MBJudgeable
ShipuraEvaluate expressions that combine floor division by powers of two with squaring modulo 1,000,000,007 and nested brackets.Medium4StackRecursion+1No attempts yet8s512 MBJudgeable
Star Pattern 18Print the size N star figure of nested triangles with alternating orientation defined recursively.Medium4RecursionMatrix+1No attempts yet1s256 MBJudgeable
Decision TreeParse a recursively defined decision tree, then for each animal walk the tree using its features and multiply node weights to get the probability.Medium4TreeRecursion+2No attempts yet5s512 MBJudgeable
Counting Ugly ExpressionsInsert +, -, or nothing between adjacent digits of a digit string, count how many of the 3^(D-1) expressions evaluate to a number divisible by 2, 3, 5, or 7.Medium4Brute forceRecursion+2No attempts yet5s512 MBJudgeable
Far Far AwayGiven a directed tree rooted at city 1 with weighted edges, find the maximum root-to-node path weight, or -1 if it stays below M.Medium4TreeDFS+2No attempts yet2s512 MBJudgeable
Obfuscated TreesDecode a tree from its obfuscated token stream, where each internal node carries an ordering code and subtree count, then print its values in pre-order.Medium4TreeRecursion+1No attempts yet2s512 MBJudgeable
Hidden PalindromeGiven a word of at most 40 lowercase letters, find the longest palindromic subsequence obtainable by deleting letters from the front and back.Medium4Dynamic programmingString+2No attempts yet2s512 MBJudgeable
N and M (7)Given N distinct numbers and a length M, print every length-M sequence drawn from the numbers with repetition allowed, deduplicated and in increasing lexicographic order.Medium4BacktrackingRecursion+2No attempts yet1s512 MBJudgeable
N and M (8)Given N distinct natural numbers and a length M, print all non-decreasing sequences of length M drawn from the numbers, in lexicographic order.Medium4BacktrackingSorting+1No attempts yet1s512 MBJudgeable
N and M (9)Given N numbers (with duplicates) and length M, print every distinct length-M selection in increasing lexicographic order, using each copy at most once.Medium4BacktrackingSorting+1No attempts yet1s512 MBJudgeable
N and M (11)Given N numbers and a length M, list every length-M sequence drawn from the numbers, allowing repeats, in increasing lexicographic order without duplicates.Medium4BacktrackingRecursion+2No attempts yet1s512 MBJudgeable
N and M (12)Given N numbers and a length M, list all non-decreasing length-M sequences drawn from the numbers with repetition, in lexicographic order.Medium4BacktrackingSorting+2No attempts yet2s512 MBJudgeable