85. Excel Sheet Column Number
mediumAsked at VercelConvert an Excel-style column title (A, B, ..., Z, AA, AB, ...) to its corresponding integer. It looks like a one-liner — and the loop is — but the question hides a real numeral-system subtlety: this is bijective base-26, a system with digits 1 through 26 and no zero. Vercel candidates report it as a screen warm-up where saying the word 'bijective' (or at least explaining why there is no zero digit) is the entire differentiator.
By Sam K., Founder, InterviewChamp.AI · Last verified
Source citations
Public interview reports confirming this problem appears in Vercel loops.
- Glassdoor (2025-12)— Vercel screen warm-up.
- LeetCode Discuss (2026-Q1)— Listed in Vercel new-grad screen recap.
Problem
Given a string columnTitle that represents the column title as appears in an Excel sheet, return its corresponding column number. A maps to 1, Z to 26, AA to 27, AB to 28 — the lettering continues like a numeral system that has no zero digit.
Constraints
1 <= columnTitle.length <= 7columnTitle consists only of uppercase English letters.columnTitle is in the range ['A', 'FXSHRXW'].
Examples
Example 1
columnTitle = "A"1Explanation: Single letters map directly: A is the 1st column. There is no letter for zero — the first hint this is not standard base-26.
Example 2
columnTitle = "AB"28Explanation: A contributes 1 * 26 = 26, B contributes 2: total 28. Note AA is 27, immediately after Z at 26 — the sequence never 'resets' through a zero.
Example 3
columnTitle = "ZY"701Explanation: Z is 26, Y is 25: 26 * 26 + 25 = 701. Multi-letter titles accumulate exactly like digits, just offset by one.
Approaches
1. Recursive base-26
title -> base26 number, like converting a decimal string to int but with base 26 and A=1.
- Time
- O(n)
- Space
- O(n) stack
function titleToNumber(columnTitle) {
if (columnTitle.length === 0) return 0;
const last = columnTitle.charCodeAt(columnTitle.length - 1) - 64;
return titleToNumber(columnTitle.slice(0, -1)) * 26 + last;
}Tradeoff: Identical arithmetic to the loop but pays O(n) call stack and string slicing for no benefit — useful only to show the recurrence value(s) = value(prefix) * 26 + digit before collapsing it into the iterative form.
2. Iterative left-to-right base-26 (optimal)
Walk the string; result = result * 26 + (char - 'A' + 1).
- Time
- O(n)
- Space
- O(1)
function titleToNumber(columnTitle) {
let n = 0;
for (const c of columnTitle) {
n = n * 26 + (c.charCodeAt(0) - 64); // 'A' = 65, so 'A' - 64 = 1
}
return n;
}Tradeoff: Single pass, O(1) space. The key insight: this is base-26 BUT with digits 1-26 instead of 0-25 (no 'zero' character).
Vercel-specific tips
Vercel grades the base-26-with-offset insight. Bonus signal: pointing out that this is bijective base-26 (no zero character) and contrasting with standard base-26 where AA would equal A. Mention the inverse problem (LC 168) where the off-by-one shows up again.
Common mistakes
- Using `c.charCodeAt(0) - 65` — that gives 0 for A, breaking the 1-indexing.
- Treating it as standard base-26 — AA would be 26, not 27.
- Forgetting to multiply by 26 before adding the new digit.
Follow-up questions
An interviewer at Vercel may pivot to one of these next:
- Excel Sheet Column Title (LC 168) — the inverse.
- Generalize to any custom alphabet.
- Base conversion in arbitrary bases.
Solve it now
Free. No sign-up. Python and JavaScript run instantly in your browser.
FAQ
Why -64 and not -65?
'A' should map to 1, not 0. The character code of 'A' is 65, so 65 - 64 = 1. This is bijective base-26.
Why isn't this standard base-26?
Because there's no 'zero' character. AA != A; AA = 27. Standard base-26 would let AA == A by leading-zero suppression.
Can the result overflow?
Not within the stated constraints — the maximum title FXSHRXW is 2,147,483,647, exactly the 32-bit integer ceiling, and JavaScript numbers handle it natively. In a fixed-width language, mention that the constraint was chosen to sit at INT_MAX on purpose.
More Vercel coding interview questions
- 1. Two Sum
- 2. Valid Parentheses
- 3. Merge Two Sorted Lists
- 4. Remove Duplicates from Sorted Array
- 5. Remove Element
- 6. Search Insert Position
- 7. Plus One
- 8. Merge Sorted Array