Topic
Math & Bit Manipulation interview problems
Number theory, combinatorics and bit tricks. 217 original problems, each with hidden test cases you can run in the browser.
84 easy112 medium21 hard
Showing 31–60 of 217 results
Three friends speak under a rule that ties honesty to who owns more cats. Use the statements, parity, divisibility and a sum bound to find Bob's cat count and the triple of counts.
Model answerlogic-puzzlecase-analysisdivisibilityparityCompute the number of sequences, the chance of exactly 3 heads, and the chance of at most 3 heads for n fair coin tosses, using binomial counting and handling small n.
Auto-gradedcombinatoricsbinomialprobabilitymathFind the minimum number of neighbor-GCD replacements to turn an entire array into ones, using shortest coprime-window search and a lower-bound argument.
Auto-gradedgcdsubarraynumber-theorycase-analysisSimulate encoding and decoding of a length-prefixed binary wire protocol with error validation.
Auto-gradedbinaryparsingencodingbit-manipulationDecide whether a positive integer pair can grow into a target pair by repeatedly adding one coordinate to the other, using reverse-step reasoning and Euclid-style reduction.
Auto-gradedmatheuclidean-algorithmreverse-simulationnumber-theoryCompute binomial probabilities that a limited stock covers random demand from a line of customers, both as at most M buyers and as exactly M buyers.
Auto-gradedprobabilitybinomialcombinatoricsmathWork out how many times a C for-loop body runs when its condition is an assignment expression rather than a comparison, and explain the final variable values.
Model answerc-languagecontrol-flowoperatorsassignment-expressionFind the optimal accept/reject rule and the game value for a symmetric alternating-roll zero-sum game, using a stationary fixed-point equation.
Auto-gradedexpected-valuegame-theoryoptimal-stoppingfixed-pointTests whether you can enumerate all primes up to a limit efficiently using a sieve instead of per-number primality tests, including the n below 2 edge case.
Auto-gradedsieveprimesnumber-theoryarraysExplain how lazy evaluation works in Python and write a generator that yields Fibonacci numbers indefinitely, with safe ways to consume it and the reasoning behind its state handling.
Model answerpythongeneratorslazy-evaluationfibonacciCompute three probabilities from a two-group mixture model: at-least-one-success over n days, a Bayesian posterior after all-success streaks, and a posterior predictive forecast.
Auto-gradedprobabilitybayesmixture-modelcomplement-ruleGiven a list of strings, count the number of contiguous substrings in each string whose characters can be permuted to form a valid palindrome.
Auto-gradedbit-manipulationhash-tablestringsprefix-sumCalculate total delivery earnings from start/end times and distances using conditional rates, rush-hour multipliers, and precision rules.
Model answermathparsingsimulationCompute where a token lands on a ring after k escalating hops, which tests spotting a prefix-sum closed form with modular arithmetic instead of simulating.
Auto-gradedmathmodular-arithmeticsimulationclosed-formCompute the interest earned on a loan using a simple (non-compounding) annual percentage rate prorated over a number of months.
Auto-gradedmathsimple-interestarithmeticfinanceCompute a baseline expected payoff and the fair prices of two coin-editing tools, using linearity of expectation, a parity invariant, and an absorbing-state argument.
Auto-gradedprobabilityexpected-valueparity-invariantmarkov-chainCompute a truncated 32-bit signed integer quotient using only shifts, addition and subtraction, handling the single overflow case and sign rules efficiently.
Auto-gradedbit-manipulationmathbinary-searchoverflowChoose a subset of words with no shared letters so the number of distinct letters covered is maximal, which suits bitmask encoding and subset search.
Auto-gradedbitmaskbacktrackingsubsetsstringsCompute the probability that three cards drawn without replacement from the cards the opponent left behind sum to exactly 15, using combinatorial counting.
Auto-gradedcombinatoricsprobabilityenumerationitertoolsImplement a class-weighted, focus-modulated binary cross-entropy directly from logits in pure Python, with stable math, input validation and sum/mean/none reductions.
Auto-gradednumerical-stabilitysigmoidloss-functionfloating-pointRaise a row-stochastic matrix to a given power and build a row-normalized transition estimate from observed index pairs, leaving rows with no data as zeros.
Auto-gradedmatrix-exponentiationmarkov-chainprobabilitycountingCompute a portfolio's one-period variance from a factor model (exposures, factor covariance, specific variances), then scale it by periods per year and take the square root.
Auto-gradedmatrixlinear-algebrafinancequadratic-formCount Monday-to-Friday days in an inclusive date range, skipping listed closure dates, using week arithmetic instead of day-by-day iteration.
Auto-gradeddatescalendararithmeticsetsGenerate the first n primes in ascending order, which tests sieve design with an upper bound derived from a count, plus handling of non-positive n.
Auto-gradedprimessievenumber-theorymathComputes the annual net contribution per card, overall portfolio profit, and the minimum number of new accounts needed to cover a marketing campaign.
Auto-gradedmathfinancial-modelingarithmeticWork out the hidden rule behind eight short numeric and fractional sequences, state the next term for each, and justify it against every given term.
Model answersequencespattern-recognitionrecurrence-relationsmental-mathCompute one row of Pascal's triangle by index, using only space proportional to the row, via an in-place update or the multiplicative binomial recurrence.
Auto-gradedpascal-trianglecombinatoricsdynamic-programmingarraysSolve parity-based string transformation via bitmasks and handle offline 2D range count queries using dynamic point-update data structures.
Model answerbit-manipulation2d-fenwick-treesweep-lineprefix-sumComputes the expected payoff of a game played with two independent six-sided dice, rounded to two decimal places.
Auto-gradedmath-bitsprobabilitysimulationCompute yearly revenue, cost, profit and per-member profit for a membership program from fees, monthly spend commission, and fixed and variable costs.
Auto-gradedmatharithmeticunit-conversionsimulation