Community Problem

Excel Sheet Column Number

Difficulty: Easy

Convert a spreadsheet column title (`A`, `Z`, `AA`, `AB`, ...) into its 1-based column number using bijective base-26.

Excel Sheet Column Number

Convert a spreadsheet column title (`A`, `Z`, `AA`, `AB`, ...) into its 1-based column number using bijective base-26.

EASY
Free
math
arrays
khalidcooper

By @khalidcooper

April 27, 2026

·

Updated May 18, 2026

1,177 views

19

Rate

I once shipped a CSV importer that kept off-by-one'ing on AA, and the bug led directly to this question on a Square onsite. The wrinkle is that this is BIJECTIVE base-26, not regular base-26: there is no zero digit, so Z + 1 == AA, not BA. Once you internalize that, the loop is two lines.

Excel Sheet Column Number

Given a string columnTitle that represents the column title as it appears in an Excel sheet, return its corresponding column number.

For example:

columnTitle  number
A            1
B            2
C            3
...
Z            26
AA           27
AB           28
...

Examples

Example 1:

  • Input: columnTitle = "A"
  • Output: 1

Example 2:

  • Input: columnTitle = "AB"
  • Output: 28
  • Explanation: 1 * 26 + 2 == 28.

Example 3:

  • Input: columnTitle = "ZY"
  • Output: 701
  • Explanation: 26 * 26 + 25 == 701.

Example 4:

  • Input: columnTitle = "FXSHRXW"
  • Output: 2147483647
  • Explanation: This is exactly 2^31 - 1, the largest 32-bit signed integer.

Constraints

  • 1 <= columnTitle.length <= 7.
  • columnTitle consists only of uppercase English letters.
  • columnTitle is in the range ["A", "FXSHRXW"].

Follow-up

Why is this not standard base-26? Because there is no zero digit. A represents 1, not 0, so AA is 1 * 26 + 1 = 27, not 1 * 26 + 0 = 26. The conversion is the same loop as base-26 but with each digit value (c - 'A' + 1) instead of (c - '0').

Solution

Hints

0/3
Hint 1
Hint 2
Hint 3
All Problems