Ctrl K

Spreadsheet Column Index

Easy
Spreadsheet columns are labeled with letters: A, B, …, Z, then AA, AB, …, AZ, BA, …, ZZ, then AAA, and so on. Given a column label label, return its position, counting from 1: A is 1, Z is 26, AA is 27.
Example 1
label='E' → 5

E is the fifth letter, so it is the fifth column.

Example 2
label='BA' → 53

After A through Z come AA through AZ (columns 27 to 52), so BA is column 53.

Example 3
label='ZZ' → 702

There are 26 one-letter and 26·26 = 676 two-letter labels, and ZZ is the last of them: 26 + 676 = 702.

Constraints
  • 1 ≤ len(label) ≤ 7
  • label consists of uppercase English letters
  • The column number is at most 2³¹ − 1
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsValue of a Roman Numeral EasySum of Binary Strings EasySpreadsheet Column Label EasyCounting Off by Threes and Fives EasyAdding Long Numbers in Strings Easy
loading Python…
Input
label='E'
Expected
5

Run checks the first 3 tests in your browser. Submit checks all 188 tests on the server, hidden ones included.