Implement the excelColumnNumber method that converts an Excel column title into its column number.

The input contains a string column representing an Excel column title. Your task is to convert it into its column number.

Excel columns work like a base-26 number system where A is 1, B is 2, and Z is 26. After Z, the next column is AA.

Example 1

Input
column (string) = AB
Returns (int) 28

Example 2

Input
column (string) = A
Returns (int) 1

Example 3

Input
column (string) = ZY
Returns (int) 701

Process the column title from left to right like a base-26 number.

For each character, multiply the current answer by 26 and add the character value. The value of a character is its position in the alphabet, where A = 1 and Z = 26.

For example, AB becomes 1 * 26 + 2 = 28.

Pseudocode:

function excelColumnNumber(column):
    result = 0
    for each character ch in column:
        value = position of ch from A to Z
        result = result * 26 + value
    return result
Ready to test your solutionRun Code checks your solution against the test cases.Shift + Enter to run

Notifications

Updates are enabled for this browser.

Receive new tutorials, articles and learning resources. You can turn updates off anytime.

Test browser code

Use this code in admin to send a test notification to this browser.