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,786 problems
TitleLevelTopicsSolvedTime limitMemory limitJudge
Red RoverGiven a route string over N, S, E, W of length at most 100, find the minimum total length of a message using one optional macro M and its definition that expands to the route.Medium6Dynamic programmingStringNo attempts yet2s512 MBJudgeable
Orderly ClassGiven two equal-length strings A and B, count the intervals in A such that reversing that interval turns A into B.Medium6StringTwo pointers+2No attempts yet2s512 MBJudgeable
Jumbled passwordGiven a string, find the smallest index past the midpoint where the suffix differs from the prefix of equal length in exactly one character.Medium6StringString matching+2No attempts yet0.5s1024 MBJudgeable
Hay BalesGiven a string of C and P, each move sorts any three consecutive characters so all C come before all P; find the minimum number of moves to fully sort the whole row.Medium6GreedyString+2No attempts yet2s512 MBJudgeable
Minimum editCompute the Levenshtein distance between two lowercase strings, using the fewest insert, delete, and replace operations to change A into B.Medium6Dynamic programmingString+2No attempts yet2s512 MBJudgeable
An Unfair PuzzleGiven two permutations of 1..n, decide whether cyclic rotations and reversals can turn the first into the second, printing good puzzle or bad puzzle.Medium6StringString matching+2No attempts yet2s256 MBJudgeable
Thinking StationFor each K from 1 to N, split the first N cars into blocks of K (dropping the remainder) and count distinct blocks up to reversal; report the K values with the maximum count.Medium6StringHash map+2No attempts yet1s256 MBJudgeable
Comma SprinklerGiven a text, repeatedly add commas before or after every occurrence of a word that already has a comma on that side, until nothing changes; print the result.Medium6GraphBFS+2No attempts yet8s1024 MBJudgeable
AnagramsGiven two equal-length uppercase strings A and B, find the minimum total number of cyclic letter increments applied to positions of A so the result is an anagram of B.Medium6GreedySorting+2No attempts yet2s512 MBJudgeable
GeneticsGiven N DNA strings of length M, find the one string that differs from every other string in exactly K positions.Medium6StringBrute force+2No attempts yet2s1024 MBJudgeable
Pseudo-Banana StringsGiven a string of B, A, N, find the minimum number of character replacements that turn it into a concatenation of blocks of the form B+ANANA(NA)*.Medium6Dynamic programmingString+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
BracketGiven a bracket pattern with some fixed brackets and some dots, count the ways to fill the dots so the whole string is a balanced bracket sequence.Medium6Dynamic programmingCombinatorics+2No attempts yet2s512 MBJudgeable
Chinese ID NumberCheck an 18-character Chinese ID: region code from a given list, birthday in 1900 to 2011, sequence code not 000, then for valid IDs report gender by odd/even sequence code. The checksum is a mod 11 weighted sum of the first 17 digits plus a digit x making the total 1, with x=10 written as 'X'.Medium6StringArray+2No attempts yet2s512 MBJudgeable
Jurassic JigsawGiven n DNA strings of length k, build a spanning tree minimizing the total Hamming distance over its edges, and print the cost plus the edges.Medium6Minimum spanning treeGraph+2No attempts yet1s512 MBJudgeable
Game NightGiven a circular arrangement of A, B, and C seats, find the minimum people to move so each team forms one contiguous block.Medium6StringSliding window+2No attempts yet1s512 MBJudgeable
Circle Cross StampsGiven a row of O and X marks printed by single circles, single crosses, and two-mark circle-cross stamps in either orientation, find the largest possible count of circle-cross stamps.Medium6Dynamic programmingGreedy+1No attempts yet2s512 MBJudgeable
ParametriziranCount pairs of equal-length words over lowercase letters and question marks that can be made identical by filling the question marks.Medium6Bit manipulationHash map+2No attempts yet3s512 MBJudgeable
Rainbow BeadsFind the longest contiguous substring of a string over R, B, V that has no equal adjacent pair under any of the three color-blind views.Medium6Two pointersSliding window+2No attempts yet1s1024 MBJudgeable
Comparing StringsGiven two lowercase strings, align them by repeating characters of either string, keeping order, and minimize the sum of absolute alphabet-position differences over aligned pairs.Medium6Dynamic programmingString+2No attempts yet1s512 MBJudgeable
Bracket String and QueriesFlip one character per query and count how many prefixes of the query sequence leave the string as a correct bracket sequence.Medium6StringPrefix sum+2No attempts yet0.5s512 MBJudgeable
Christmalo.winGiven N short strings, pick two and a shared letter to splice their prefix and suffix, minimizing the total deleted characters.Medium6StringHash map+2No attempts yet1s1024 MBJudgeable
Balanced StringCount binary strings of length n where every prefix has at most one more 0 than 1 or one more 1 than 0, modulo 16769023.Medium6Dynamic programmingCombinatorics+2No attempts yet0.5s512 MBJudgeable
Gathering BallsGiven a row of red and blue balls, find the minimum number of jumps (moving only one color) to group each color together.Medium6GreedyString+2No attempts yet1s512 MBJudgeable
JOIOJIGiven a string of J, O, and I, find the longest contiguous substring with equal counts of all three letters.Medium6Prefix sumHash map+2No attempts yet1s512 MBJudgeable
Typo SquattingFor each domain name, count how many other given domains differ from it in exactly one character position.Medium6Hash mapString+2No attempts yet4s512 MBJudgeable
HaikuGiven a set of syllables, decide whether the three input phrases can each be split into syllables so their syllable counts are 5, 7, and 5.Medium6Dynamic programmingString+2No attempts yet1s512 MBJudgeable
Sculptural ProjectGiven a string of work and market days, cancel the fewest days so materials never run out and end at zero.Medium6Dynamic programmingPrefix sum+2No attempts yet2s512 MBJudgeable
Hard Sculptural ProjectGiven a string of 'w' (work, consume 1) and 'o' (rest, gain 1), delete the fewest characters so every prefix has more gains than work and the total balances, then count the ways.Medium6Dynamic programmingGreedy+2No attempts yet2s512 MBJudgeable
Assessing GenomesCompute each DNA string's smallest repeating unit length, then pair the two sets of scores to minimize the sum of squared differences.Medium6StringSorting+2No attempts yet2s512 MBJudgeable
Is There a Divisor?Given a digit string, find a base B and a divisor X (both at most 10^9) making the string's value composite in base B, or report that none exists.Medium6MathNumber theory+2No attempts yet2s512 MBJudgeable
LJUSTRead lines up to ENDOFINPUT, wrap each to a width C, and justify any line whose length is at least floor(C/2) by spreading spaces left to right.Medium6StringImplementation+2No attempts yet2s512 MBJudgeable
ASLRDRReorder a string with adjacent swaps so it becomes a palindrome, reporting the minimum number of swaps or Impossible.Medium6GreedyTwo pointers+2No attempts yet2s512 MBJudgeable
DISHFor each pair of strings, output a shortest string that contains both input strings as substrings.Medium6StringDynamic programming+2No attempts yet2s512 MBJudgeable
JJOOII 2Given a string of J, O, I and a level K, delete characters from the ends or middle to obtain K J's then K O's then K I's, minimizing middle deletions.Medium6GreedyTwo pointers+2No attempts yet2s512 MBJudgeable
CatCount how many distinct strings you can form by joining a non-empty suffix of a with a non-empty prefix of b.Medium6StringString matching+2No attempts yet2s512 MBJudgeable
Balls of BumaGiven a row of colored balls, count the color and insertion position pairs that make the chain reaction remove every ball.Medium6StringImplementation+2No attempts yet3s512 MBJudgeable
Two PrefixesGiven strings s and t, count distinct strings formed by concatenating a non-empty prefix of s with a non-empty prefix of t.Medium6StringString matching+2No attempts yet1s512 MBJudgeable
Page NumberGiven a digit string, count the ways to split it into two positive integers i and n with no leading zeros, representing "Page i of n".Medium6StringImplementation+2No attempts yet2s512 MBJudgeable
DNA Deletions and Protein CountCount, modulo 1e9+7, the distinct proteins obtainable by deleting some nucleotides from a DNA string and translating the remaining codons via a given table.Medium7Dynamic programmingGreedy+2No attempts yet2s128 MBJudgeable
Palindrome FactoryCompute the minimum number of insertions, deletions, replacements, and at most one swap needed to turn a given string into a palindrome.Medium7Dynamic programmingString+1No attempts yet2s128 MBJudgeable
Largest Room Number 2Given per-digit purchase costs and a budget, find the largest number (no leading zero) affordable, then output its length and its first and last 50 digits.Medium7GreedyMath+2No attempts yet2s128 MBJudgeable
Restore an Addition EquationFill the ? digits in an addition equation A+B=C with digits (no leading zeros) so the sum holds, maximizing C then A.Medium7Dynamic programmingGreedy+2No attempts yet2s128 MBJudgeable
Palindrome Word SequencesCount ordered sequences of given words, reused any number of times, whose concatenation has exact length L and forms a palindrome.Medium7Dynamic programmingString matching+2No attempts yet2s128 MBJudgeable
Palindrome SmartCount palindromic strings of length 1 to N built from lowercase letters that use at most K distinct letters, modulo 1234567891.Medium7CombinatoricsMath+2No attempts yet3s128 MBJudgeable
Group Word ReconstructionReconstruct the unique group word, where every letter forms one contiguous block, by arranging all given unordered pieces, or report impossibility or multiple solutions.Medium7GraphString+2No attempts yet2s128 MBJudgeable
Ideal StringBuild the lexicographically smallest length-N string where each character's total occurrence count equals the position of its first appearance, or output -1 if none exists.Medium7GreedyDynamic programming+2No attempts yet2s128 MBJudgeable
Number of Strings Matching Exactly K PatternsCount lowercase strings that match exactly K out of N given letter/question-mark patterns of equal length, modulo 1,000,003.Medium7CombinatoricsBit manipulation+2No attempts yet2s128 MBJudgeable
Syum CrosswordCount distinct grid arrangements of four given words split into two horizontal and two vertical words that cross each other exactly once under strict adjacency and gap rules.Medium7CombinatoricsBrute force+2No attempts yet2s128 MBJudgeable
Oh SejunConstruct the lexicographically smallest length-N repeating sequence of U/R moves that makes a robot land exactly on a target cell, or report impossibility.Medium7GreedyMath+2No attempts yet2s128 MBJudgeable
MusicInsert non-consecutive rest symbols into three note sequences to equalize their lengths while maximizing a column-matching score, or report impossibility.Medium7Dynamic programmingString+1No attempts yet2s128 MBJudgeable
Top Shelf of the BookshelfPick up to 10 book titles, sorted lexicographically, so that no two neighboring titles share the same letter at any aligned alphabetic position, maximizing total preference score.Medium7Dynamic programmingString+2No attempts yet2s128 MBJudgeable
String Period PredictionUsing KMP-style prefix functions, find for every prefix the largest period-like split point and sum these values across the whole string.Medium7String matchingString+1No attempts yet2s128 MBJudgeable
Increasing SequenceGiven a digit string up to 80 characters, split it into a strictly increasing sequence of integers (leading zeros allowed) minimizing the last number's value.Medium7Dynamic programmingString+1No attempts yet2s128 MBJudgeable
Counting Base RepresentationsCount the ways to split a digit string into a base suffix and a sequence of no-leading-zero digit values all less than that base.Medium7Dynamic programmingString+1No attempts yet2s128 MBJudgeable
Compare Tree Traversal PathsGiven two 0/1 Euler-tour strings from DFS traversals of a tree rooted at the same vertex, decide whether both could come from the same underlying tree.Medium7TreeString+1No attempts yet2s128 MBJudgeable
Mobile Binary NumberGiven a nested-bar mobile whose bars may each be flipped independently, find the K-th lexicographically smallest distinct binary string obtainable across all flip combinations.Medium7Dynamic programmingRecursion+2No attempts yet1s128 MBJudgeable
DNA SimilarityFind the lexicographically smallest longest common subsequence of two DNA strings where adjacent picked characters in each string must be within index-distance K.Medium7Dynamic programmingStringNo attempts yet1s128 MBJudgeable
I²CParse raw I2C SCL/SDA bit-sample sequences to decode start/stop bits, address, direction, ACKs, and data bytes, reporting the transaction or the first protocol error.Medium7SimulationString+2No attempts yet1s128 MBJudgeable
How Was Typesetting Done in the Past?Simulate historical typesetting rules by replacing letter combinations with ligature codes and correctly choosing long s versus short s per word based on multiple context-dependent rules.Medium7StringImplementation+1No attempts yet1s128 MBJudgeable
Optimizing Mobile Phone Text EntryPartition the 26 letters into K ordered contiguous groups (max 8 each) to minimize frequency-weighted key presses, breaking ties by lexicographically smallest concatenated output.Medium7Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
Secret WordsGiven secret words and a target string, find minimum total rearrangement cost to build the target by concatenating (possibly rearranged) copies of the words, or -1 if impossible.Medium7Dynamic programmingString+1No attempts yet1s128 MBJudgeable
ASCII StreetGiven a street string and multiple pattern tiles, count how many street positions are never covered by any occurrence of any pattern, requiring efficient multi-pattern matching like Aho-Corasick.Medium7String matchingTrie+1No attempts yet4s512 MBJudgeable
Tap DanceMaintain, after each single-character flip in a binary string, the length of the longest alternating (no two equal adjacent) substring, supporting online point updates.Medium7Segment treeString+1No attempts yet1s128 MBJudgeable
A=SInsert plus signs between digits of a huge number A so the resulting sum equals a small target S, using as few plus signs as possible.Medium7Dynamic programmingString+1No attempts yet1s128 MBJudgeable
Closest Permutation NumbersGiven digit string a and a multiset of digits from b, find the smallest permutation of b's digits that is >= a and the largest that is < a, with no leading zero.Medium7GreedyString+1No attempts yet1s128 MBJudgeable
Longest Repeated SubstringGiven a lowercase string of up to 200000 characters, compute the length of the longest substring that occurs at least twice, allowing overlaps.Medium7StringBinary search+1No attempts yet1s256 MBJudgeable
Sierpinski TriangleGiven a Sierpinski-triangle sub-triangle's name string, output the names of all triangles it leans against based on the fractal's midpoint-subdivision structure.Medium7StringRecursion+2No attempts yet1s128 MBJudgeable
Formula SubstitutionGiven two formula strings with variables 0 and 1, find basic-formula substitutions for both variables that make the two formulas syntactically identical, similar to unification.Medium7RecursionString matching+2No attempts yet1s128 MBJudgeable
Character EquationGiven a recursive definition of a huge string T through variable concatenation equations, determine whether a pattern P is a subsequence of T without expanding T explicitly.Medium7Dynamic programmingString+2No attempts yet1s256 MBJudgeable
Complicated ExpressionsParse an arithmetic expression with parentheses and reprint it with every redundant parenthesis removed while preserving exact operator precedence and associativity semantics.Medium7StringRecursion+1No attempts yet1s128 MBJudgeable
CaptionGiven a fixed current pixel grid layout and a new text with letter width k and spacing bounds smin/smax, find the layout minimizing flipped pixels using DP over positions and letters with precomputed per-letter overlap costs.Medium7Dynamic programmingString+1No attempts yet1s128 MBJudgeable
High SecurityGiven up to 50000 length-5 passwords over 62 characters, count pairs of passwords for each Hamming distance from 0 to 5.Medium7StringCombinatorics+2No attempts yet3s256 MBJudgeable
Auxiliary Question of the UniverseGiven a fragment of an arithmetic expression grammar (numbers, plus, parentheses), find the minimum insertions needed to make it a valid expression while keeping the fragment as a subsequence.Medium7Dynamic programmingString+1No attempts yet1s128 MBJudgeable
KINA Is Not AbbreviationGiven a text, find the abbreviation (initials of a consecutive word window) that is unambiguous per the stated rules and maximizes letter-count reduction, breaking ties lexicographically.Medium7String matchingHash map+2No attempts yet2s512 MBJudgeable
DFAGiven a finite set of words, compute the minimum number of states of a DFA recognizing exactly that language.Medium7TrieDynamic programming+1No attempts yet1s128 MBJudgeable
A+BGiven forbidden strings V, find the lexicographic index sum of A and B among all strings orthogonal to V, then output the string at that index modulo the count.Medium7MathCombinatorics+1No attempts yet2s64 MBJudgeable
DecipheringCount the ways to split an unspaced text into dictionary words, group them into sentences, and match each sentence to a valid part-of-speech rule, capping the huge counts.Medium7Dynamic programmingString+2No attempts yet2s64 MBJudgeable
AmbiguousSplit a scrambled, space-free string into a unique sequence of dictionary words matching letter multisets, first and last letters, reporting ambiguity or impossibility.Medium7Dynamic programmingString+2No attempts yet1s128 MBJudgeable
The Best Name for Your BabyGiven a context-free grammar-like rewriting rule set, find the lexicographically smallest terminal string of exactly length l derivable from start symbol S.Medium7Dynamic programmingString+2No attempts yet1s128 MBJudgeable
MysteryGiven a character set and N integers in [-X, X] where X is one less than the set size, output the unique length-N string those integers encode.Medium7StringMath+2No attempts yet1s128 MBJudgeable
HyperdromeCount substrings of S whose characters can be rearranged into a palindrome, where only the parity of each letter's count matters.Medium7Bit manipulationPrefix sum+2No attempts yet2s128 MBJudgeable
AbbreviationsGiven ignored stopwords, an abbreviation, and a sentence, count the distinct ways to split the abbreviation into pieces matched as subsequences of the meaningful words in order.Medium7Dynamic programmingString+2No attempts yet1s128 MBJudgeable
OctagonsGiven words over {a,b,c} describing paths in the labeled (3,3,3,8) octagon tessellation, decide whether each path returns to its start.Medium7MathString+1No attempts yet1s128 MBJudgeable
Life FormsGiven up to 100 DNA strings, find every longest contiguous substring that appears in strictly more than half of them, printed in alphabetical order.Medium7StringBinary search+2No attempts yet2s128 MBJudgeable
Cousin StringsFind the smallest n such that x is an n-th cousin of y, where each cousin step requires a common string reachable by deleting at most half of each string, or report that no n exists.Medium7GraphBFS+2No attempts yet1s128 MBJudgeable
Help!Given two patterns of literal words and named placeholders, find the lexicographically smallest word phrase matching both, or output a minus sign if none exists.Medium7StringHash map+2No attempts yet1s128 MBJudgeable
Edit Step LaddersGiven a lexicographically sorted dictionary, find the longest sequence of words where each consecutive pair differs by one insertion, deletion, or substitution, and the sequence follows dictionary order.Medium7Dynamic programmingString+2No attempts yet1s128 MBJudgeable
DoubletsGiven a dictionary, answer queries for the shortest chain of words where consecutive words differ in exactly one letter, choosing the lexicographically smallest chain.Medium7BFSGraph+2No attempts yet1s128 MBJudgeable
BraceletsGiven two circular strings, find the longest common subsequence that can be read in the same or opposite orientation on the two bracelets, and report twice its length.Medium7Dynamic programmingString+2No attempts yet30s256 MBJudgeable
BeadsGiven two 13-bead rings, each with 13 gray and 13 yellow beads, find the fewest swaps of a 3-bead block between the rings to put all gray on top.Medium7BFSString+2No attempts yet1s128 MBJudgeable
YO!Count paint-over patterns of a short string whose remaining letters, read left to right, form one or more dictionary words without overlap.Medium7Dynamic programmingString+2No attempts yet1s128 MBJudgeable
Syntax IncludedParse each HTML-like string against the given grammar and decide whether it is syntactically valid.Medium7StringRecursion+2No attempts yet1s128 MBJudgeable
Stems SellApply ordered pattern-to-replacement rewrite rules, which support *, V, C, and back-references, to every word in each paragraph.Medium7StringString matching+2No attempts yet1s128 MBJudgeable
Shape NumberGiven a chain code, take its first difference mod 8 and print the lexicographically smallest cyclic rotation of that sequence.Medium7StringString matching+1No attempts yet2s128 MBJudgeable
ClickomaniaGiven a string over uppercase letters, decide whether the one dimensional Clickomania puzzle can be fully cleared.Medium7Dynamic programmingIntervals+1No attempts yet10s128 MBJudgeable
The Sorcerer's DonutOn a torus grid of letters, find the longest string that can be read twice along two non-self-overlapping straight runs in the 8 directions, breaking ties lexicographically.Medium7StringBrute force+2No attempts yet1s128 MBJudgeable
Word AdditionCount letter-to-digit assignments that make a cryptarithmetic addition of up to 12 words valid, with no leading zeros and distinct digits per letter.Medium7BacktrackingBrute force+2No attempts yet40s128 MBJudgeable
Code TheftNormalize two sets of source lines and find the longest consecutive run of lines common to both, reporting the length and which files achieve it.Medium7StringHash map+1No attempts yet1s128 MBJudgeable
Gooseberry Tart BASICImplement a fast interpreter for a small BASIC subset with LET, GOTO, IF, FOR/NEXT, OUT, and COMMENT, printing each program's output.Medium7ImplementationSimulation+2No attempts yet1s128 MBJudgeable