Pattern visualizer
Excel Sheet Column Number
This is base-26 arithmetic, but Excel columns are 1-indexed (A=1, not 0) — so each character contributes result*26 + (its 1-based letter value) instead of the usual 0-based digit value. Animated on: s = "AB" — convert the column title to its column number..
Base-26, but 1-indexed (A=1..Z=26)
time O(L)space O(1)step 1 / 8
A
[0]B
[1]line 1
Process each character left to right, building result = result*26 + value.
Pseudocode
1FUNCTION titleToNumber(s):2 result = 03 FOR each character ch in s:4 value = position of ch in the alphabet (A=1 .. Z=26)5 result = result * 26 + value6 RETURN result
← / → step · space play · Home restart