Excel Sheet Column Title - Problem

Ever wondered how Excel generates those column headers? A, B, C... Z, AA, AB... This problem asks you to reverse-engineer Excel's column naming system!

Given an integer columnNumber, return its corresponding column title as it appears in an Excel sheet.

The mapping works like this:

  • A → 1
  • B → 2
  • C → 3
  • ...
  • Z → 26
  • AA → 27
  • AB → 28
  • ...

This is essentially a base-26 numeral system using letters A-Z, but with a twist - there's no zero! It's like counting with a bijective base-26 system.

Input & Output

example_1.py — Single Letter
$ Input: columnNumber = 1
Output: "A"
💡 Note: The first column in Excel is labeled 'A', corresponding to number 1.
example_2.py — Double Letter Start
$ Input: columnNumber = 28
Output: "AB"
💡 Note: After Z (26), we have AA (27), then AB (28). This follows the bijective base-26 pattern.
example_3.py — Large Number
$ Input: columnNumber = 701
Output: "ZY"
💡 Note: 701 converts to ZY in Excel's column system. This demonstrates the mathematical conversion: (701-1) gives us the right digits in base-26.

Constraints

  • 1 ≤ columnNumber ≤ 231 - 1
  • The result will always be a valid Excel column title
  • No leading zeros - this is bijective base-26

Visualization

Tap to expand
Excel Column System: Bijective Base-26Single Letters (1-26):A1B2...Z26Double Letters (27+):AA27AB28...AZ52Conversion Algorithm1. while (columnNumber > 0):2. columnNumber -= 1 // Handle 1-indexed3. char = 'A' + (columnNumber % 26)4. columnNumber /= 26Example: 28 → ABStep 128-1=2727%26=1→'B'Step 21-1=00%26=0→'A'Result: ABBuilt right→left💡 Key Insight: Subtract 1 first because there's no 'zero' character in this systemThis makes it a bijective base-26 system (every number maps to exactly one string)
Understanding the Visualization
1
Single Letters (1-26)
A through Z represent columns 1 through 26
2
Double Letters Start
After Z, we get AA (27), AB (28), etc.
3
Mathematical Pattern
This is bijective base-26: no zero, direct mapping
4
Conversion Algorithm
Subtract 1, divide by 26, use remainder for character
Key Takeaway
🎯 Key Insight: Excel columns use bijective base-26 - subtract 1 to convert from 1-indexed to 0-indexed, then use standard base conversion with A-Z representing digits 0-25.
Asked in
Microsoft 35 Google 28 Amazon 22 Meta 15
89.3K Views
Medium Frequency
~15 min Avg. Time
2.8K Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen