We have discussed Conversion from column number to Excel Column name. In this post, reverse is discussed.
Given a column title as appears in an Excel sheet, return its corresponding column number.
A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28
Input : A Output : 1 Input : AA Output : 27
The process is similar to binary to decimal conversion.
For example, to convert AB, we do 26 * 1 + 2.
As another example, to convert CDA, we do
3*26*26 + 4*26 + 1
=>26(3*26 + 4)+ 1
=>26(0*26 + 3*26 +4)+1
Time Complexity: O(n) where n is length of input string.
This article is contributed by Sahil Rajput. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Given a string, find its first non-repeating character
- Find the smallest window in a string containing all characters of another string
- Given a number, find the next smallest palindrome
- Find if a string is interleaved of two other strings | DP-33
- Find the first non-repeating character from a stream of characters
- Find Excel column name from a given column number
- How to turn off a particular bit in a number?
- Given a sorted dictionary of an alien language, find order of characters
- Find if an array of strings can be chained to form a circle | Set 1
- Given two strings, find if first string is a subsequence of second
- Given a binary string, count number of substrings that start and end with 1.
- Find if a given string can be represented from a substring by iterating the substring “n” times
- Factorial of a large number
- Find all distinct palindromic sub-strings of a given string
- Find maximum depth of nested parenthesis in a string