171. Excel Sheet Column Number
easyAsked at Goldman SachsConvert an Excel column title like 'AB' to its column number (28). Goldman Sachs uses this base-26 conversion problem to confirm you can derive the closed-form arithmetic without Googling — a foundational skill for the trading-tools team.
By Alex Chen, Founder, InterviewChamp.AI · Last verified
Source citations
Public interview reports confirming this problem appears in Goldman Sachs loops.
- Glassdoor (2026-Q1)— Goldman Sachs SWE candidates report Excel Sheet Column Number as a 'derive base-26' question with the title-to-number direction.
- LeetCode Discuss (2025-10)— Excel Sheet Column Number is in the top-25 of LeetCode's Goldman Sachs company tag.
Problem
Given a string columnTitle that represents the column title as it appears in an Excel sheet, return its corresponding column number. For example: A → 1, B → 2, Z → 26, AA → 27, AB → 28, ZY → 701.
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. Horner's method for base-26 (optimal)
Treat the title as a base-26 number with 'A' = 1. result = result * 26 + (ch - 'A' + 1) for each char.
- Time
- O(n)
- Space
- O(1)
function titleToNumber(columnTitle) {
let result = 0;
for (let i = 0; i < columnTitle.length; i++) {
result = result * 26 + (columnTitle.charCodeAt(i) - 64);
}
return result;
}Tradeoff: Single pass, constant space. The Horner-style accumulation is the canonical answer — it's a base-26 number with 1-indexed digits.
2. Power-of-26 from the right
For each character from the right, multiply by 26^position.
- Time
- O(n)
- Space
- O(1)
function titleToNumberPow(columnTitle) {
let result = 0;
let pow = 1;
for (let i = columnTitle.length - 1; i >= 0; i--) {
result += (columnTitle.charCodeAt(i) - 64) * pow;
pow *= 26;
}
return result;
}Tradeoff: Same asymptotic complexity but uses a running power variable instead of multiplying-then-adding. Slightly more arithmetic but exposes the place-value intuition more clearly — useful for explaining the base-26 framing.
Goldman Sachs-specific tips
Goldman Sachs is grading two things: (1) do you see this as 'base-26 number conversion' rather than 'special Excel trick', and (2) can you handle the 1-indexed quirk (A=1 not A=0). Spend 30 seconds at the whiteboard mapping 'AB' = 1*26 + 2 = 28 before writing code. This frames the problem and earns you 'clear thinker' points on the rubric.
Common mistakes
- Treating 'A' as 0 instead of 1 — gives 'AA' = 26 instead of 27.
- Mixing the digit-mapping direction (some candidates accidentally do char - 'A' giving 0-25 and forget to +1).
- Reaching for a lookup table instead of arithmetic, which works but signals you didn't see the base-26 structure.
Follow-up questions
An interviewer at Goldman Sachs may pivot to one of these next:
- Reverse: convert a column number to its Excel title (LeetCode #168, this problem's pair).
- Generalize to arbitrary base-N with 1-indexed digits.
- What if columns could be lowercase or mixed-case? (Define the mapping, fold case before parsing.)
Solve it now
Free. No sign-up. Python and JavaScript run instantly in your browser.
FAQ
Why is Excel column numbering 1-indexed instead of 0-indexed?
Because Excel's spec is human-facing — column A is column 1, not column 0. The 1-indexing is what makes the conversion subtly trickier than a standard base-26 parse. In standard base-26 'AA' = 00 = 0; in Excel 'AA' = 27.
Will the integer overflow for very long column titles?
Not within the given constraints — the max valid input 'FXSHRXW' converts to 2^31 - 1, exactly INT_MAX. The problem is sized so that the answer always fits in a 32-bit signed int. In a 64-bit language this is academic; in 32-bit it's intentional.
Free learning resources
Curated free links for this problem.
Practice these live with InterviewChamp.AI
Drill Excel Sheet Column Number and other Goldman Sachs interview questions under real-loop conditions with instant feedback on your reasoning, complexity claims, and code.
Practice these live with InterviewChamp.AI →