InterviewBit - Excel Column  

by ne on 2021-09-29 under Algo/DS/Problems

This problem is a property of InterviewBit (www.interviewbit.com).

Full details of the question, and if you want to try it out yourself, proceed to interviewbit : https://www.interviewbit.com/problems/excel-column-number/

Here's the implementation:

 


public class Solution {
    public int titleToNumber(String A) {
        int m=(int)Math.pow(26,(A.length()-1));
        return rec(A, m==0?1:m);
    }
    private int rec(String a, int m){
        if(a.length()==0) return 0;
        return (m*(a.charAt(0)-64))+rec(a.substring(1),m/26);
    }
}


Happy Coding !