Learner Level
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) =
ABReturns (int)
28Example 2
Input
column (string) =
AReturns (int)
1Example 3
Input
column (string) =
ZYReturns (int)
701Process 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 resultReady to test your solutionRun Code checks your solution against the test cases.Shift + Enter to run