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 → 1B → 2C → 3- ...
Z → 26AA → 27AB → 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
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.
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code