Skip to main content

168. Excel Sheet Column Title

easyAsked at Goldman Sachs

Given a positive integer, return its corresponding Excel column title (e.g. 28 → 'AB'). Goldman Sachs asks this immediately after Column Number to test whether you noticed why the inverse needs an n-1 correction — most candidates miss it.

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 this paired with #171 in the same interview as 'see if they notice the offset'.
  • LeetCode Discuss (2025-11)Excel Sheet Column Title sits next to its pair in Goldman's company-tag top-25.

Problem

Given an integer columnNumber, return its corresponding column title as it appears in an Excel sheet. A → 1, B → 2, Z → 26, AA → 27, AB → 28, ZY → 701, AAA → 703.

Constraints

  • 1 <= columnNumber <= 2^31 - 1

Examples

Example 1

Input
columnNumber = 1
Output
"A"

Example 2

Input
columnNumber = 28
Output
"AB"

Example 3

Input
columnNumber = 701
Output
"ZY"

Example 4

Input
columnNumber = 2147483647
Output
"FXSHRXW"

Approaches

1. Subtract-1 trick then base-26 (optimal)

Excel columns are 1-indexed. Decrement by 1 BEFORE each modulo to convert to 0-indexed digits, then map and divide.

Time
O(log n)
Space
O(log n)
function convertToTitle(columnNumber) {
  const chars = [];
  while (columnNumber > 0) {
    columnNumber--;
    const digit = columnNumber % 26;
    chars.push(String.fromCharCode(65 + digit));
    columnNumber = Math.floor(columnNumber / 26);
  }
  return chars.reverse().join('');
}

Tradeoff: Logarithmic in the column number, linear in the output length. The columnNumber-- on every iteration is the part 80% of candidates miss — without it, Z and AA both map to 'Z'.

2. Naive base-26 without offset (incorrect)

Treat columnNumber as base-26 with digits 1-26 mapped to A-Z.

Time
O(log n)
Space
O(log n)
function convertToTitleNaive(columnNumber) {
  const chars = [];
  while (columnNumber > 0) {
    const digit = columnNumber % 26;
    chars.push(String.fromCharCode(65 + digit - 1));
    columnNumber = Math.floor(columnNumber / 26);
  }
  return chars.reverse().join('');
}

Tradeoff: Wrong — fails on 26 (returns '@' because 26 % 26 = 0 then 0 + 65 - 1 = 64 = '@'). Goldman explicitly tests with 26 because that's the diagnostic case for whether you handled the 1-indexed offset.

Goldman Sachs-specific tips

Goldman Sachs interviewers are specifically watching for whether you handle 26. If you whiteboard 26 → 'Z' and 27 → 'AA' before writing code, you'll catch the offset. If you don't, you'll write the buggy version and the interviewer will calmly type 26 into the test runner. The columnNumber-- before the modulo is the entire grade.

Common mistakes

  • Forgetting the n-- before the modulo, which breaks Z (26), AZ (52), BZ (78), etc.
  • Forgetting to reverse the digits at the end (you build them LSB-first).
  • Treating the problem as plain base-26 (which has digits 0-25) instead of Excel-base-26 (digits 1-26 with no zero).

Follow-up questions

An interviewer at Goldman Sachs may pivot to one of these next:

  • Why doesn't this base have a zero? (Because Excel never displays an empty cell as 'column 0' — the mapping is by design and forces the offset.)
  • Reverse: column title to number (this problem's pair, LeetCode #171).
  • Generalize to base-N with 1-indexed digits.

Solve it now

Free. No sign-up. Python and JavaScript run instantly in your browser.

Output

Press Run or Cmd+Enter to execute

FAQ

Why does columnNumber-- before the modulo fix the offset?

Because the Excel digit set is {1..26}, not {0..25}. Subtracting 1 shifts to the standard 0-25 set, after which (n-1) % 26 + 'A' gives the right character, and (n-1) / 26 propagates correctly. Without the -- you can never reach 'AA' because (26 % 26) is 0 and (26 / 26) is 1, but '0+A' isn't valid.

Why does the input go up to 2^31 - 1?

Because 2^31 - 1 = 2147483647, which converts to 'FXSHRXW' (7 letters) — the largest Excel column. The constraint is tuned to test whether your algorithm stays correct at INT_MAX.

Free learning resources

Curated free links for this problem.

Practice these live with InterviewChamp.AI

Drill Excel Sheet Column Title 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 →