Excel Sheet Column Number
An easy Math interview guide. Task statement, worked examples, intuition, and step-by-step solutions.
- Topic
- Math
- Sheets
- 1
- Core for
- 13 roles
The problem
Given a string representing an Excel column title as it appears in a spreadsheet, return its corresponding column number. The numbering follows the pattern where A=1, B=2, ..., Z=26, AA=27, AB=28, and so on.
Example 1
- Input
- columnTitle = "A"
- Output
- 1
- Why
- A corresponds to column number 1.
Example 2
- Input
- columnTitle = "AB"
- Output
- 28
- Why
- AB = 1 * 26 + 2 = 28. This is like a base-26 number where A=1 and B=2.
Example 3
- Input
- columnTitle = "ZY"
- Output
- 701
- Why
- ZY = 26 * 26 + 25 = 701. Z=26 and Y=25 in the 1-indexed system.
Constraints
- 1 <= columnTitle.length <= 7
- columnTitle consists only of uppercase English letters
- columnTitle is between 'A' and 'FXSHRXW'
How to think about it
Updated 2026-09-29Excel column numbering is positional base-26, with the unique twist that digits run from 1 to 26 rather than 0 to 25. Reading the string left to right, each step shifts the accumulated total by a factor of 26 before adding the value of the current letter.
Approaches, worst first
Right-to-left positional powers
time O(n) · space O(1)
Traverse characters from right to left, multiplying each character code offset by 26^pos. Computing explicit powers introduces avoidable exponentiation calls or power table lookups.
Horner polynomial evaluationWrite this one
time O(n) · space O(1)
Iterate left to right across the string, updating total as total × 26 + (char - 'A' + 1). This mirrors standard Horner evaluation for polynomial radix conversion with zero auxiliary space.
Where people lose marks · 2
- Mapping 'A' to 0 instead of 1, which confuses 'A' with leading zeroes and produces 0 instead of 1 for 'A'.
- Accumulating into a signed 32-bit integer when parsing the maximum column 'FXSHRXW'; its value is 2147483647, which fits exactly in a signed 32-bit integer, but an intermediate off-by-one or wrong base can overflow.
The theory behind it
Math — the ground this problem stands on. All Math problems
What Math is
Algorithmic math is the application of number properties, modular arithmetic, and geometric patterns to compute results without simulating every step. Rather than filling memory buffers with millions of simulated counters or walking endless loops, mathematical formulation uses identities like prime factorization, digit extraction, and greatest common divisors to jump directly to target answers through closed-form rules.
When to reach for it
Reach for mathematical techniques when problem bounds are massive, such as constraints reaching ten to the eighteenth power where simulation is impossible. Strong prompts mention prime generation, greatest common divisor calculations, modular inverses, fast exponentiation, digit reversals, or combinatorial arrangements. If brute-force counting produces memory overflow or time limit exceeded warnings, algebraic reorganization is the intended path.
How the pattern works
Focus on numeric constraints and potential overflows before writing expressions. Break numbers into constituent digits using modulo ten to peel least significant figures and integer division to shrink scale. For divisibility, apply Euclid's remainder theorem repeatedly until remainder drops to zero. Apply modulo arithmetic at every intermediate addition and multiplication stage rather than once at the end, preventing values from spilling beyond standard numeric register limits.
More Math problems
Target Roles
Core requirement for 13 roles:
Track in your role's order
Pick your target role and all 370 problems resequence to what that interview actually asks.
Start freeProblem set and role mapping as of .