Interview Question
Devops Engineer Interview
-Mumbai
H2O.aiA programming question ? Related to excel spread sheet. The question goes this way. columns will go infinitely : A , B.......................Z,AA,AB............AZ,AAA................ZZZZ so interviewer wanted me to choose a programming language of choice and pass the column name and print corresponding column number. A - 1 B- 2 Z - 26 AA - 27 1 + 26 AZA - 1 + 26 + 26 +
AnswerAdd Tags
Interview Answers
3 Answers
▲
0
▼
I tried solving it with python I gave some solution it didn't worked well.
Anonymous on
▲
0
▼
public class Column { static int getColumnPosition(String cell) { int columnposition = 1; int row = 0; int j = 0; char[] cellAsArray = cell.toCharArray(); char column = cellAsArray[cellAsArray.length - 1]; for (int i=0; i = 'A' && letter <= 'Z') { letterPosition += 1 + letter - 'A'; } return letterPosition; } public static void main(String[] args) { int position = getColumnPosition("ZZ"); System.out.println("Position is " +position); } }
Anonymous on
▲
0
▼
num = 0 for char in list('AZA'): num = num + ord(char) - ord('A') + 1 return num
Anonymous on
Add Answers or Comments
To comment on this, Sign In or Sign Up.