Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plz help in my code soln bhaiya! 10 test cases are passed but n=5473578 is giving one character wrong. #13

Open
raj-khanna1 opened this issue Oct 3, 2023 · 1 comment

Comments

@raj-khanna1
Copy link

raj-khanna1 commented Oct 3, 2023

10 test cases are passed but n=5473578 is giving one character wrong.
soln..

class Solution{
    public:
    void clm_name(long long int n,string&ans,vector<char>&alpha){
        if(n<=26){
            ans.push_back(alpha[n-1]);
            return;
        }
        long long clm_no=n/26;
        int row_no=n%26;
        clm_name(clm_no,ans,alpha);
        ans.push_back(alpha[row_no-1]);
        if(row_no==0)ans.push_back('Z');
    }
    string colName (long long int n)
    {   vector<char>alpha(26);
        int d=65;
        for(int i=0;i<26;i++)
        alpha[i]=d+i;
        string ans;
        clm_name(n,ans,alpha);
        return ans;
    }
};
@raj-khanna1
Copy link
Author

class Solution{ public: void clm_name(long long int n,string&ans,vector<char>&alpha){ if(n<=26){ ans.push_back(alpha[n]); return; } long long clm_no=n/26; int row_no=n%26; clm_name(clm_no-1,ans,alpha); ans.push_back(alpha[row_no]); //if(row_no==0)ans.push_back('Z'); } string colName (long long int n) { vector<char>alpha(26); int d=65; for(int i=0;i<26;i++) alpha[i]=d+i; string ans; clm_name(n-1,ans,alpha); return ans; } };

now it's working but why we are subtracting -1 from the n bhaiya??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant