KatInterview

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.

Problems217

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-analysisdivisibilityparity
  • Compute 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-gradedcombinatoricsbinomialprobabilitymath
  • Find 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-analysis
  • Simulate encoding and decoding of a length-prefixed binary wire protocol with error validation.

    Auto-gradedbinaryparsingencodingbit-manipulation
  • Decide 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-theory
  • Compute 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-gradedprobabilitybinomialcombinatoricsmath
  • Work 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-expression
  • Find 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-point
  • Tests 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-theoryarrays
  • Explain 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-evaluationfibonacci
  • Compute 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-rule
  • Given 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-sum
  • Calculate total delivery earnings from start/end times and distances using conditional rates, rush-hour multipliers, and precision rules.

    Model answermathparsingsimulation
  • Compute 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-form
  • Compute the interest earned on a loan using a simple (non-compounding) annual percentage rate prorated over a number of months.

    Auto-gradedmathsimple-interestarithmeticfinance
  • Compute 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-chain
  • Compute 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-searchoverflow
  • Choose 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-gradedbitmaskbacktrackingsubsetsstrings
  • Compute the probability that three cards drawn without replacement from the cards the opponent left behind sum to exactly 15, using combinatorial counting.

    Auto-gradedcombinatoricsprobabilityenumerationitertools
  • Implement 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-point
  • Raise 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-chainprobabilitycounting
  • Compute 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-form
  • Count Monday-to-Friday days in an inclusive date range, skipping listed closure dates, using week arithmetic instead of day-by-day iteration.

    Auto-gradeddatescalendararithmeticsets
  • Generate 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-theorymath
  • Computes the annual net contribution per card, overall portfolio profit, and the minimum number of new accounts needed to cover a marketing campaign.

    Auto-gradedmathfinancial-modelingarithmetic
  • Work 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-math
  • Compute 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-programmingarrays
  • Solve 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-sum
  • Computes the expected payoff of a game played with two independent six-sided dice, rounded to two decimal places.

    Auto-gradedmath-bitsprobabilitysimulation
  • Compute 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

More topics