KatInterview

Topic

Math & Bit Manipulation interview problems

Number theory, combinatorics and bit tricks. 216 original problems, each with hidden test cases you can run in the browser.

Problems216

84 easy111 medium21 hard

Showing 1–30 of 216 results

  • Derive and evaluate the closed-form expected value and variance for the number of inversions in a uniformly random permutation.

    Auto-gradedmathcombinatoricsstatisticsprobability
  • Evaluate floating-point powers with integer exponents using logarithmic time binary exponentiation without standard library power methods.

    Auto-gradedmathbinary-exponentiationbit-manipulation
  • Find the optimal sequence of deposit and collection moves to maximize expected value in an unobserved two-container game.

    Auto-gradedprobabilityexpected-valuegreedymath
  • Label each pair of circles by their geometric relationship using exact integer squared-distance comparisons and a strict rule order, including degenerate radius-zero cases.

    Auto-gradedgeometryinteger-arithmeticcase-analysissimulation
  • Compute the headcount of two specialist worker types so a component quota splits exactly 2:1 with every worker at full capacity, or report that no such staffing exists.

    Auto-gradedmathratiosdivisibilitymodular-arithmetic
  • Calculate the exact win probability in a dice duel where one player uses an optimal single blind reroll strategy.

    Auto-gradedmathprobabilitygreedy
  • Implement full-batch gradient descent for a one-feature least-squares line, standardizing the input, and map the learned parameters back to the original scale.

    Auto-gradedgradient-descentlinear-regressionnumericalfeature-scaling
  • Simulate customer buy and sell orders against fractional inventory, trading only whole shares with the market, and emit ordered transfer logs and final balances.

    Auto-gradedsimulationstring-parsinginteger-arithmetichash-map
  • Compute the minimum total steps to ferry every item to a single target cell on an open grid, carrying one at a time, using Manhattan distances and a smart choice of the first pickup.

    Auto-gradedgreedymanhattan-distancegridmath
  • Count how many runners, released one per time unit, cross a track without ever sharing a cell at the same integer time with a sentry that bounces back and forth inside a fixed range.

    Model answersimulationmodular-arithmeticperiodic-motionparity
  • Invert the bit at a given index in a non-negative integer using bitwise operations.

    Model answermath-bitsbit-manipulationmath
  • Compute the expected number of same-rank card pairs in a hand drawn without replacement, using linearity of expectation over pairs of cards.

    Auto-gradedprobabilityexpectationcombinatoricslinearity-of-expectation
  • Computes the exact binomial tail probability P(X > k) and its Poisson approximation parameterised by lambda = n * p.

    Auto-gradedmathstatisticsprobability
  • Split a run of consecutive IPv4 addresses into the fewest aligned power-of-two prefix blocks using 32-bit integer and lowest-set-bit reasoning.

    Auto-gradedbit-manipulationgreedyipv4cidr
  • Write iterative and recursive factorial functions alongside a sequence of integer squares, focusing on input validation, edge cases, and stack vs. loop complexity.

    Model answermathrecursioniterationpython
  • Determine how many positive integers can serve as the starting element of a sequence of consecutive positive integers that sums to a target value.

    Auto-gradedmathnumber-theoryarithmetic-progression
  • Track a pool that only grows, sized to cover each load reading with fixed-capacity workers; tests ceiling division and running-maximum reasoning with large values.

    Auto-gradedsimulationprefix-maximumceiling-divisionarrays
  • Implement population variance on a list of numbers without external libraries, handling empty and single-element inputs and choosing a numerically sound approach.

    Auto-gradedvariancestatisticsfloating-pointarrays
  • Find the smallest palindromic integer strictly larger than a non-negative integer, using the left half of the digits and carry handling, including the all-9s case.

    Auto-gradedpalindromedigitsmathcarry
  • Compute the sum of integers from 1 to n divisible by at least one of 3, 5, or 7, counting each integer once, which tests overlap handling and inclusive bounds.

    Auto-gradedmathinclusion-exclusioniterationdivisibility
  • Compute a float raised to a signed 32-bit integer power in logarithmic time and constant space, handling negative exponents, zero bases and the most negative exponent.

    Auto-gradedbinary-exponentiationfloating-pointedge-casesiteration
  • Find the prime at a given 1-based position in ascending order, which tests sieving, bounding the search range, and complexity reasoning.

    Auto-gradedprimessievenumber-theorymath
  • Build a cumulative distribution from sampled density points using exact integration of a piecewise-linear curve, then answer many query points with correct boundary behavior.

    Auto-gradednumerical-integrationbinary-searchprefix-sumsprobability
  • Given population size and individual adoption probability, calculate key expectation, probability, and conditional probability metrics under Bernoulli assumptions.

    Auto-gradedmathprobabilitystatisticsnumerical-methods
  • Decide whether one positive integer point can become another by repeatedly replacing a coordinate with the coordinate sum, for values up to 10^18, by reversing moves with modulo.

    Auto-gradedmatheuclidean-algorithmmoduloreverse-thinking
  • Compute a birthday-collision threshold exactly and by approximation, plus expected minimum gap and tail probability for random points on a circle, with a Poisson comparison.

    Auto-gradedprobabilitymathbirthday-paradoxpoisson-approximation
  • Compute a floating-point base raised to a signed 32-bit integer exponent in logarithmic time, including negative exponents, using repeated squaring.

    Auto-gradedbinary-exponentiationmathbit-manipulationfloating-point
  • Build a fixed unit-economics report for a card launch: portfolio P&L, partnership uplift, bonus payback time, and the zero-profit loss rate.

    Auto-gradedmathsimulationunit-economicsdictionaries
  • Given selection priors and ball counts for several containers, calculate the posterior probability of drawing from a specific container after observing a target outcome.

    Auto-gradedmathprobabilitybayes-theoremarrays
  • 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

More topics