Skip to content
DeepForgeby svx
All problems
EasyAlgorithmsal-050

Excel Column Number

Problem

Convert an Excel column title such as A, Z, AA or ZY to its 1-based column number.

Process characters left to right treating the title as a base-26 number where A is 1 rather than 0: result = result * 26 + (letter position). Assume s contains only uppercase letters.

Hint

Shift the running value by one base-26 digit per character, with A having value 1.

Test cases

case 1
in: ["A"]
expected: 1
case 2
in: ["Z"]
expected: 26
case 3
in: ["AA"]
expected: 27
case 4
in: ["ZY"]
expected: 701
case 5
in: ["AZ"]
expected: 52
Starter codePython
def excel_column_number(s):
    # Your code here
    pass

5 test cases · run your code against them in the editor