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,020 problems
TitleLevelTopicsSolvedTime limitMemory limitJudge
Queen CollisionsGiven groups of queens placed along arithmetic progressions on an n by n board, count pairs that share a row, column, or diagonal with no queen between them.Medium7MathSorting+2No attempts yet1s128 MBJudgeable
Trie, Again TrieGiven trees encoded in preorder, find the repeated subtree whose replacement by one shared copy saves the most nodes, breaking ties by size then preorder.Medium7TreeDFS+2No attempts yet1s128 MBJudgeable
Walk in the ParkCount trees visible from at least one given horizontal or vertical path, where a tree is visible if no other tree blocks the line of sight.Medium7SortingHash map+2No attempts yet1s128 MBJudgeable
String EquationsDecide whether a subset of distinct short strings and their repeats can be split into two groups whose multiset union of characters is identical.Medium7MathNumber theory+2No attempts yet1s128 MBJudgeable
Incidental PointsFor each test case, choose two points whose segment contains the most other given points and report that count.Medium7GeometryHash map+2No attempts yet5s128 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
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
Functional Programming CountsImplement an interpreter for a tiny functional language with variables, single-parameter functions, and call-count profiling per definition line.Medium7ImplementationSimulation+2No attempts yet1s128 MBJudgeable
PointsCount the distinct straight lines in 3D space that pass through at least three of the given points.Medium7GeometryHash map+2No attempts yet1s128 MBJudgeable
Acrobat ReaderFor each test case, decide whether two sets of N points match under rotation by a multiple of 90 degrees, translation, and positive uniform scaling, with reflections disallowed.Medium7GeometryHash map+2No attempts yet1s128 MBJudgeable
Comparing CodeFind the longest run of HAL's lines that matches a run of RBN's lines up to injective variable renaming and swapping the two right-hand operands.Medium7String matchingHash map+1No attempts yet1s128 MBJudgeable
Electrical PollutionGiven consistent anomaly measurements at grid points, determine for each queried point whether its anomaly is uniquely forced by propagation along rows and columns of generators on the diagonal line.Medium7Union-findGraph+2No attempts yet1s128 MBJudgeable
Cocircular PointsFor each test case with up to 100 distinct points, find the largest subset that lies on one common circle and print its size.Medium7GeometryHash map+2No attempts yet5s128 MBJudgeable
Insidious BrandingCount quadruples of dictionary words A, B, C, D with A+B = C+D and length(A) < length(C).Medium7Hash mapStringNo attempts yet2s128 MBJudgeable
Party InvitationsInviting cow 1 forces whole groups once all but one member is in; find the smallest set of cows that must be invited.Medium7GraphBFS+2No attempts yet1s128 MBJudgeable
MirrorsGiven N small mirrors tilted at 45 degrees, find the first mirror whose flip lets a horizontal ray from the origin reflect to reach point (a,b).Medium7GeometrySimulation+2No attempts yet1s128 MBJudgeable
Concurrently Balanced StringsGiven K parenthesis strings of length N, count index ranges whose substring is balanced in all K strings at once.Medium7Hash mapPrefix sum+2No attempts yet1s128 MBJudgeable
Wrong DirectionsGiven a command string of F, L, and R, count the distinct final positions reachable by changing exactly one character to a different one.Medium7SimulationHash map+2No attempts yet1s128 MBJudgeable
Cow PhotographyGiven five orderings of N cows where each cow moves in at most one photo, reconstruct the original intended order.Medium7SortingImplementation+2No attempts yet1s128 MBJudgeable
Cows on IceBessie slides on ice until a rock stops her; find the minimum number of pushes to move from her start cell to the goal cell.Medium7BFSGraph+2No attempts yet1s128 MBJudgeable
Gold Balanced LineupGiven N cows each with a K-bit feature ID, find the longest contiguous range where every one of the K features appears the same number of times.Medium7Hash mapPrefix sum+2No attempts yet1s128 MBJudgeable
SolitaireGiven two placements of four identical pieces on an 8x8 board, decide whether slides and jumps reach the second from the first within 8 moves.Medium7BFSGraph+2No attempts yet1s128 MBJudgeable
Corporate IdentityGiven up to 4000 short lowercase strings, find the longest string that occurs as a contiguous substring of every one, breaking ties by lexicographic order.Medium7StringString matching+2No attempts yet1s128 MBJudgeable
MobileDecide whether two mobiles, given as rooted binary structures with negated weight labels, can be rotated to look identical.Medium7TreeDFS+2No attempts yet1s128 MBJudgeable
Guessing Game IIGiven up to 8 guess/response pairs, decide whether the 4-digit secret is already unique, find the smallest next guess that identifies it, or report that none can.Medium7Brute forceHash map+2No attempts yet2s128 MBJudgeable
Shopping OffersGiven regular item prices and bundle offers, find the minimum cost to buy exactly the listed quantities without buying extras.Medium7Dynamic programmingArray+2No attempts yet1s512 MBJudgeable
Uniform SubtreesGiven a parenthesis-encoded tree, list every distinct uniform subtree (same child count at each depth) in lexicographic order.Medium7TreeDFS+2No attempts yet3s128 MBJudgeable
Cake CuttingCount the distinct rectangular pieces that can be left after repeatedly halving a cake into two equal halves with equal candle counts.Medium7Divide and conquerRecursion+1No attempts yet1s1024 MBJudgeable
Lazy Math InstructorDecide whether two arithmetic expressions with left-to-right equal-precedence operators are identical as polynomials over single-letter variables.Medium7Hash mapString+2No attempts yet1s128 MBJudgeable
Lattice AnimalsCount free n-polyominoes (up to rotation and reflection) that fit inside a w by h rectangle, with n up to 10.Medium7BacktrackingBrute force+2No attempts yet2s128 MBJudgeable
Computer DialogueGiven file names split into name and extension parts, simulate the alternating 'I don't know' messages between two clients and list files still possible after M messages.Medium7SimulationHash map+2No attempts yet1s128 MBJudgeable
UFO Cubes in RoswellGiven a cube with mirrors at integer points, trace every downward light ray and report how many exit each face and how many deflections they took.Medium7SimulationImplementation+2No attempts yet2s1024 MBJudgeable
ArtinalsInterpret a small language over hereditarily finite sets, evaluating assignments, expressions and relations, and print reduced canonical set representations.Medium7StringImplementation+2No attempts yet1s512 MBJudgeable
NeighboursGiven n peaks on a w by h grid, count non-peak grid points by how many of their four axis directions contain a peak.Medium7SortingHash map+2No attempts yet2s64 MBJudgeable
Counting Rectangles Drawn with SegmentsCount axis-aligned rectangles whose four sides are fully covered by the union of the given collinear segments.Medium7GeometryHash map+2No attempts yet1s16 MBJudgeable
Texture TileGiven an N x N image, find the largest square subimage whose top row equals its bottom row and left column equals its right column.Medium7Dynamic programmingHash map+1No attempts yet2s256 MBJudgeable
PointsGiven a pattern point set and up to 20 query sets, decide for each whether it is similar to the pattern under rotation, translation, reflection, and scaling.Medium7GeometrySorting+2No attempts yet3s128 MBJudgeable
PalindromesGiven n distinct palindromes, count ordered pairs whose concatenation is also a palindrome, with total length up to 2,000,000.Medium7StringHash map+2No attempts yet5s256 MBJudgeable
TrainsAfter each of m car swaps, track the largest number of trains that ever shared each train's exact colour string.Medium7Hash mapString+1No attempts yet1s128 MBJudgeable
Algorithm SpeedupDecide whether a recursively defined Boolean function F on two sequences returns 1 or 0, where F strips the longest prefix and suffix that drop some value.Medium7RecursionHash map+2No attempts yet8s128 MBJudgeable
WalkGiven up to one million missing strings among n-bit names, decide whether two present names are connected through single-bit flips avoiding blocked names.Medium7BFSGraph+2No attempts yet5s256 MBJudgeable
Fiber Optic NetworkReserve bandwidth on tree paths for connect requests when capacity allows and release per-pair reservations on disconnect.Medium7Segment treeTree+1No attempts yet1s128 MBJudgeable
Guessing GameFind the largest prefix of interval parity answers that stays consistent with some 0/1 sequence of length one billion.Medium7Union-findPrefix sum+1No attempts yet1s128 MBJudgeable
Weights and ScalesPlace one gray weight on the empty pan, then repeatedly merge each balanced scale in the nested tower, and report the fewest weights that can remain.Medium7Prefix sumHash mapNo attempts yet1s128 MBJudgeable
Lost ListsRebuild the lexicographically smallest increasing list of distinct positive integers matching each sorted pairwise sum list, or print -1 when none exists.Medium7BacktrackingSorting+1No attempts yet1s128 MBJudgeable
Longest Common SubstringFind the length of the longest substring shared by two lowercase strings and print the lexicographically smallest one of that length.Medium7String matchingBinary search+2No attempts yet1s256 MBJudgeable
Conditional StatementsGiven one-variable if lines that switch on numbered lights, delete as many lines as possible without changing which lights turn on for any input values.Medium7IntervalsHash map+1No attempts yet1s128 MBJudgeable
Nearby GravitationCount pairs of 3D points whose Euclidean distance is smaller than k for each test case.Medium7Hash mapGeometryNo attempts yet5s128 MBJudgeable
Hack ProtectionCount the subarrays of the given array whose bitwise XOR equals their bitwise AND.Medium7Bit manipulationPrefix sum+2No attempts yet1s128 MBJudgeable
Directional ResemblanceFind the pair with the smallest nonzero angle among up to 120000 3D vectors per dataset, where some vectors come from a given pseudorandom generator.Medium7GeometrySorting+1No attempts yet10s128 MBJudgeable
Endless Candy PartyFor each s from 1 to N, find the smallest day k on which exactly s tables share the same floor(b_i/k) candies per person.Medium7MathHash map+1No attempts yet2s128 MBJudgeable
Hash functionCount the length-N lowercase words whose repeated multiply-by-33 xor hash modulo 2^M equals K.Medium7Divide and conquerHash map+2No attempts yet3s256 MBJudgeable
Fair PhotographyAfter sorting cows by position, find the widest contiguous group containing at least K breeds with each present breed appearing equally often.Medium7Prefix sumHash mapNo attempts yet1s128 MBJudgeable
LanguagesGuess the language of each 100-symbol excerpt, learning online from the correct answer returned after every guess, and maximize accuracy over 10000 turns.Medium7SimulationImplementation+2No attempts yet10s256 MBJudgeable
Palindromic PathsCount distinct palindromic strings spelled by right-down paths from the top-left to the bottom-right of an N by N letter grid.Medium7DFSHash map+1No attempts yet1s256 MBJudgeable
Attacked squaresAfter each rook relocation on a large board, count squares where the xor of powers of rooks in the same row or column is nonzero.Medium7Bit manipulationHash map+1No attempts yet2s64 MBJudgeable
Digit DivisionCount the ways to split a digit string into contiguous blocks so each block is divisible by m, modulo 1e9+7.Medium7Dynamic programmingMath+1No attempts yet1s512 MBJudgeable
Boring Planet PairsCount the planet pairs whose path xor is zero before any deletion and after each edge removal in order.Medium7Union-findHash mapNo attempts yet1s64 MBJudgeable
SymmetryGiven up to 100000 planar points per test case, decide whether any line reflects the set onto itself.Medium7GeometryHash map+1No attempts yet2s256 MBJudgeable
OOPCount for each pattern with one asterisk how many given words equal it after replacing the asterisk with any string, possibly empty.Medium7String matchingHash map+1No attempts yet2s512 MBJudgeable
Joy's TerritoryCount the unit squares with all four corners visited by repeating the same N-step walk for K days from each day's endpoint.Medium7GeometrySimulation+2No attempts yet1s256 MBJudgeable
Reassembling the Glass CowCount the triples of scattered pieces that rebuild the colored figurine after rotation, reflection, and shifting.Medium7Brute forceGeometry+2No attempts yet5s512 MBJudgeable
gWheels (Large)Decide whether pedal, middle, and tire gear choices with two different middle gears produce each target speed ratio.Medium7Number theoryHash mapNo attempts yet15s512 MBJudgeable
Snake Game SimulationSimulate a snake that grows on checkerboard food on a wrapping board with timed turns and report its length after death or one billion steps.Medium7SimulationQueue+2No attempts yet5s512 MBJudgeable
Log Set (Small)Reconstruct the original integer multiset from the frequencies of all its subset sums, breaking ties by sorted order.Medium7BacktrackingSorting+1No attempts yet5s512 MBJudgeable
Symmetric Trees (Large)Decide whether a color-painted tree can be drawn in the plane with a vertical line of symmetry.Medium7TreeRecursion+2No attempts yet5s512 MBJudgeable
Diamond InheritanceProcess class declarations in order, accepting each only if the name is fresh, all parents exist, and no diamond forms.Medium7GraphDFS+1No attempts yet2s512 MBJudgeable
GCD TableGiven all N^2 pairwise gcd values of a hidden sequence in random order, recover the sequence.Medium7MathNumber theory+2No attempts yet2s512 MBJudgeable
Celtic SymmetryGiven up to 1000 distinct integer points in the plane, count the distinct lines of symmetry of the set.Medium7GeometryHash map+2No attempts yet2s512 MBJudgeable
Longest palindromic substringFind the length of the longest contiguous substring of S that reads the same forwards and backwards.Medium7StringBinary search+1No attempts yet0.5s512 MBJudgeable
Easy ReadingGiven a book text and a picture of painted cells, find the shortest prefix-contiguous text segment whose pen strokes draw exactly that picture up to translation.Medium7String matchingHash map+1No attempts yet2s256 MBJudgeable
BabelGiven M words, each shared by two languages, find the shortest word sequence from an origin to a destination language where adjacent words differ in first letter.Medium7GraphShortest path+2No attempts yet2s512 MBJudgeable
Distinct AND values of subsequencesCount how many distinct values can appear as the bitwise AND of some subsequence of a given array, including the empty subsequence whose AND is 0.Medium7Bit manipulationDynamic programming+2No attempts yet2s512 MBJudgeable
Jazz JourneyGiven a fixed closed tour and ticket prices for one-way and round-trip fares, find the minimum cost to cover every leg of the tour.Medium7GraphGreedy+1No attempts yet5s512 MBJudgeable
Pascal's Hyper-PyramidsCompute the distinct multinomial coefficients on the base layer of a D-dimensional Pascal hyper-pyramid of height H, printed in ascending order.Medium7Dynamic programmingCombinatorics+2No attempts yet2s512 MBJudgeable
Happy sequenceGiven a non-happy sequence, count and list every single-element replacement that makes all adjacent absolute differences exactly the set 1..N-1.Medium7ArrayHash map+1No attempts yet1.5s256 MBJudgeable
Lasers and MirrorsGiven a laser, a barn, and up to 100,000 posts, find the fewest posts to mount mirrors on so the beam travels from laser to barn.Medium7GraphBFS+1No attempts yet2s512 MBJudgeable
Sherlock and Watson Gym Secrets (Large)Count ordered pairs (i, j), i != j, i, j 1..N, with i^A + j^B divisible by K, output mod 1e9+7.Medium7Number theoryMath+2No attempts yet5s512 MBJudgeable
ParrotsGiven N parrot sentences and one written sequence, decide whether distinct words can interleave so that each parrot's words stay in order and no word repeats.Medium7SimulationGreedy+2No attempts yet1s512 MBJudgeable
Dice Straight (Large)Each die shows six distinct numbers; choose at most one number per die so the chosen values form a consecutive run, and maximize its length.Medium7GraphDynamic programming+2No attempts yet30s512 MBJudgeable
Equinox Roller CoasterGiven stable grid points, find the largest axis-aligned square whose four corners are all stable points, and output its side length.Medium7Hash mapGeometry+2No attempts yet5s512 MBJudgeable
Round the world ticketCount distinct city sequences, starting and ending at ZAG, that can be flown using a subsequence of the ordered coupons, modulo 1e9+7.Medium7Dynamic programmingHash map+1No attempts yet5s512 MBJudgeable
Palindromic PartitionsSplit a string into chunks so the chunk sequence is a palindrome, and report the maximum number of chunks possible.Medium7StringGreedy+2No attempts yet10s128 MBJudgeable
AlchemyGiven starting substances and reactions that each require holding a whole set of substances to produce another set, find everything Josko can eventually obtain.Medium7GraphBFS+2No attempts yet1s64 MBJudgeable
Similarity of SubtreesFor every node, count how many nodes share its depth profile in the rooted tree; sum the number of pairs with identical profiles.Medium7TreeDFS+2No attempts yet2s512 MBJudgeable
Thor's JourneyIn a perfect binary tree of up to 2^17-1 nodes with node weights, count for each query (start node A, target sum D) how many nodes B lie on a path from A with sum D.Medium7TreePrefix sum+2No attempts yet2s512 MBJudgeable
EmpireSimulate a tree of kingdoms and wars: process each battle in order, transfer vassal subtrees on losses and successful rebellions, then report the root kingdoms sorted by ASCII order.Medium7TreeSimulation+2No attempts yet1s256 MBJudgeable
TextbooksGiven up to 16 priced book titles and a target word of length at most 10, find the cheapest subset of books whose letters can be rearranged to form the target.Medium7Bit manipulationDynamic programming+2No attempts yet1s512 MBJudgeable
Bingo TiesGiven n 5x5 bingo cards where only rows count as winning lines, find whether any two cards can complete their winning rows simultaneously on the same called number.Medium7Hash mapImplementation+2No attempts yet2s512 MBJudgeable
ImputationAssign A, T, C, or G in place of each '?' on tree leaves to minimize total transition costs along edges, summed over all string positions independently.Medium7Dynamic programmingTree+2No attempts yet2s512 MBJudgeable
CowpatibilityCount pairs of cows whose five favorite ice-cream flavors are pairwise disjoint, with up to 50000 cows and flavors up to 10^6.Medium7MathBit manipulation+2No attempts yet2s512 MBJudgeable
Selling RNA StrandsGiven N RNA strings, answer M queries that count strings matching a prefix P and suffix Q.Medium7String matchingHash map+2No attempts yet1.5s1536 MBJudgeable
Sum Source DetectionFor each queried sum X, find every open holder that appears in all valid subsets making X, where secret values must each be below the smallest open value.Medium7Dynamic programmingHash map+2No attempts yet2s512 MBJudgeable
Matrix GameGiven an N by M matrix, it asks who wins a take-away game where a move subtracts 1 to K from the leftmost nonzero entry of some row.Medium7Game theoryGreedy+2No attempts yet0.5s512 MBJudgeable
Longest Common SubstringGiven up to 10 lowercase strings, each up to 100,000 characters, find the length of the longest substring shared by all of them.Medium7StringBinary search+2No attempts yet2s512 MBJudgeable
IspitDecide whether some block of K consecutive columns can have its letters shuffled within each row so that two rows become equal.Medium7Sliding windowHash map+2No attempts yet2s512 MBJudgeable
Alphabet StringCount distinct strings formed by sorting the distinct characters of every substring of an uppercase string and removing duplicates.Medium7StringHash map+2No attempts yet1s256 MBJudgeable
Choosing a BiasGiven N friends and M members, each friend lists acceptable members; decide if a distinct member can be assigned to each of the N friends.Medium7GraphString+2No attempts yet2s256 MBJudgeable
Beer MugsGiven a string of N characters over 20 brands, find the longest substring that is a palindrome after permuting it freely.Medium7Bit manipulationHash map+2No attempts yet2s512 MBJudgeable
Flight PlansEach airport lists either its outgoing destinations or its non-destinations; find the fewest flights from s to t in the resulting implicit graph.Medium7GraphBFS+2No attempts yet1s512 MBJudgeable