Array ( [0] => [1] => questions [2] => Strings [3] => Find-Excel-Column ) Strings | Find Excel Column | THE INQUISITIVE





Find Excel Column

LEVEL:Beginner

Description

Given a number N. You have to find the respective column name of given number in excel sheet.

Input Format

First line contains the number N.

Output Format

Print the column name


Example 1:

Input
26
Output
Z
Example 2:

Input
52
Output
AZ
Example 3:

Input
676
Output
YZ

oops

Login to see Discussion




Approach

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.

oops

Login to see Solution