Array ( [0] => [1] => questions [2] => Strings [3] => Find-Excel-Column )
Given a number N. You have to find the respective column name of given number in excel sheet.
First line contains the number N.
Print the column name
26
Z
52
AZ
676
YZ
Login to see Discussion
step-i) create a string builder with name answer
step-ii) get remainder by dividing the number with 26
step-iii)if remainder is 0 append Z to string builder and update N = N/26 -1
step-iv)else append rem-1 + 'A' by casting it to char and update N = N/26
step-v) repeat steps ii to iv till N is greater than 0
step-vi) return reverse of the string builder
Time Complexity: O(logn)
Space Complexity: O(logn)
Note :
Let us know if you can come up with a better approach, mail us at support@theinquisitive.in Your approach will be reviewed and posted with credits to you.
Login to see Solution