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
// C++ program to return title to resul
// of excel sheet.
// Returns resul when we pass title.
// This process is similar to binary-to-
// decimal conversion
result = 0;
& c : s)
result *= 26;
result += c -
// Driver function
cout << titleToNumber(
) << endl;
Time Complexity = O(n) where n is length of input string.
Disclaimer: This does not belong to TechCodeBit, its an article taken from the below
source and credits.
source and credits:http://www.geeksforgeeks.org/find-excel-column-number-column-title/
We have built the accelerating growth-oriented website for budding engineers and aspiring job holders of technology companies such as Google, Facebook, and Amazon
If you would like to study our free courses you can join us at
http://www.techcodebit.com. #techcodebit #google #microsoft #facebook #interview portal #jobplacements