85. Excel Sheet Column Number
mediumAsked at VercelConvert an Excel-style column title (A, B, ..., Z, AA, AB, ...) to its corresponding integer. Vercel asks this for the base-26 arithmetic — same shape as converting their build-ID alphanumeric prefixes to lookup indices.
By Alex Chen, 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.
Constraints
1 <= columnTitle.length <= 7columnTitle consists only of uppercase English letters.columnTitle is in the range ['A', 'FXSHRXW'].
Examples
Example 1
columnTitle = "A"1Example 2
columnTitle = "AB"28Example 3
columnTitle = "ZY"701Approaches
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
// Same complexity as iterative; mention iterative.Tradeoff: Iterative is cleaner.
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.
Practice these live with InterviewChamp.AI
Drill Excel Sheet Column Number and other Vercel interview questions under real-loop conditions with instant feedback on your reasoning, complexity claims, and code.
Practice these live with InterviewChamp.AI →