Excel Sheet Column Number - Problem
Ever wondered how Excel magically converts column titles like A, B, AA, ZY into numbers behind the scenes? Here's your chance to decode the mystery!
Given a string columnTitle that represents the column title as it appears in an Excel sheet, return its corresponding column number.
Think of it as a base-26 number system where:
A→ 1B→ 2C→ 3- ...
Z→ 26AA→ 27AB→ 28- ...
Your task is to convert any valid Excel column title into its numeric equivalent.
Input & Output
example_1.py — Single Character
$
Input:
columnTitle = "A"
›
Output:
1
💡 Note:
A is the first column, so it corresponds to 1
example_2.py — Two Characters
$
Input:
columnTitle = "AB"
›
Output:
28
💡 Note:
AB = A×26 + B = 1×26 + 2 = 28. After Z(26), we get AA(27), then AB(28)
example_3.py — Boundary Case
$
Input:
columnTitle = "ZY"
›
Output:
701
💡 Note:
ZY = Z×26 + Y = 26×26 + 25 = 676 + 25 = 701
Constraints
- 1 ≤ columnTitle.length ≤ 7
- columnTitle consists only of uppercase English letters
- columnTitle is in the range ["A", "FXSHRXW"]
Visualization
Tap to expand
Understanding the Visualization
1
Understand the Pattern
A=1, B=2, ..., Z=26, AA=27, AB=28, ...
2
Apply Base-26 Logic
Each position represents a power of 26
3
Calculate from Left to Right
Multiply by 26 and add current character value
4
Get Final Result
The accumulated value is our answer
Key Takeaway
🎯 Key Insight: Excel columns use a bijective base-26 system where each position represents powers of 26, but with 1-based indexing instead of 0-based.
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code