← Back to challenges

Excel Sheet Column Number

PythonHardlanguage_fundamentalsnumbersstrings

Instructions

Given a column title as it appears in an Excel sheet return its corresponding column number.

The number is computed in the following way:

A -> 1
B -> 2
C -> 3
...
Z -> 26
AA -> 27
AB -> 28
...

Examples

title_to_number("A") ➞ 1

title_to_number("R") ➞ 18

title_to_number("AB") ➞ 28

Notes

  • 1 <= len(s) <= 7
  • s consists only of uppercase English letters.
python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.