← Back to challenges

Excel Sheet Column Number

JavaScriptHardlanguage_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

titleToNumber("A") ➞ 1

titleToNumber("R") ➞ 18

titleToNumber("AB") ➞ 28

Notes

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