Problem statement

https://binarysearch.com/problems/The-Accountant/

Solution

Equal to leetcode 0168. Excel Sheet Column Title

Complexity

It is O(log n) for time and space.

Code

class Solution:
    def solve(self, n):
        ans = []
        while n > 0:
            n, q = divmod(n-1, 26)
            ans += [chr(ord("A") + q)]
            
        return "".join(ans[::-1])