Excel Sheet Column Number
An easy Math problem included in Love Babbar 450. Below: the roles whose interviews prioritise this topic, and how to practise it.
- Topic
- Math
- Sheets
- 1
- Core for
- 13 roles
- Platform
- LeetCode
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-09Excel 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.
What each operation costs
| Operation | Time |
|---|---|
| greatest common divisor via euclidean algorithm | O(log(min(a, b))) |
| modular exponentiation by repeated squaring | O(log n) |
| prime sieve of eratosthenes up to n | O(n log log n) |
What usually goes wrong with Math
- Allowing 32-bit signed integer overflow during intermediate multiplications before modulo reduction is applied, producing negative or truncated results.
- Failing to handle negative inputs in modulo arithmetic, producing negative remainders in languages that implement truncated rather than floored division.
- Dividing by zero when the denominator or remainder becomes zero at unexpected edge boundary values like empty sets or singletons.
Which roles need this problem
Math is a core topic for these 13 roles — if you're targeting one of them, this problem is early in your path, not optional.
Secondary for 7 more roles, including Security Engineer, Performance Engineer, Site Reliability Engineer.
Track this in your role's order
Pick your target role and all 370 problems — including this one — resequence to what that interview actually asks. Free.
Start freeMore Math problems
Problem set and role mapping as of .