Math interview questions
Practice 12 questions on math. Each runs in a real in-browser editor with Jest tests and a worked, diagram-backed solution.
12 questions
- MEDIUM
Base Converter
PREMIUMConvert a number's string representation between any two bases from 2 to 36 — parse the digits in the source base, then re-emit them in the target base.
25 minJavaScript - MEDIUM
BigInt String Arithmetic
PREMIUMAdd and multiply arbitrarily large non-negative integers given as decimal strings, using digit-by-digit schoolbook arithmetic with carries.
25 minJavaScript - MEDIUM
Excel Column ↔ Number
Convert between Excel column titles and numbers in both directions — A is 1, Z is 26, AA is 27 — the classic bijective base-26 system with no zero digit.
25 minJavaScript - MEDIUM
Fast Power
Raise a base to an integer exponent in logarithmic time using exponentiation by squaring, handling negative exponents.
25 minAlgorithms - MEDIUM
GCD / LCM
Compute the greatest common divisor with Euclid's algorithm and the least common multiple, for two numbers or a whole list.
25 minAlgorithms - MEDIUM
Integer Square Root
Compute the integer square root — the floor of the real square root — using Newton's method, without Math.sqrt.
25 minAlgorithms - MEDIUM
Prime Check / Sieve
Test whether a number is prime and generate all primes up to n with the Sieve of Eratosthenes.
25 minAlgorithms - MEDIUM
Roman Numerals ↔ Integer
Convert between Roman numerals and integers in both directions, handling subtractive notation like IV, IX, and XL.
25 minJavaScript - MEDIUM
Round to Precision
Round, floor, and ceil a number to N decimal places without the classic floating-point drift — 1.005 must round to 1.01, not 1.00.
25 minJavaScript - MEDIUM
String to Number (parseInt)
Reimplement JavaScript's parseInt — skip leading whitespace, read an optional sign and radix prefix, consume valid digits for the base, and stop at the first invalid character.
25 minJavaScript - MEDIUM
Weighted Random Pick
Pick items at random in proportion to their weights using prefix sums and a binary search, with an injectable RNG so picks are testable.
25 minAlgorithms - HARD
Integer to English Words
PREMIUMSpell out a non-negative integer in English words — break it into groups of three digits and name each group with its scale word.
40 minJavaScript