Skip to content

Case for A[] = {0} and A.size()=1 is not included in problem: numbers-of-length-n-and-value-less-than-k. #1

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

Open
PrathamMeena opened this issue Aug 21, 2019 · 1 comment

Comments

@PrathamMeena
Copy link

int the recursive function
`int rec(const vector& A, int B, const vector& C, int pos)
{
if(B == 0) {
return 0;}

int n = A.size();
int i, count = 0;
for(i = 0; i < n; i++) {
    if(A[i] >= C[pos]) {
        break;
    }
    count++;
}

if(pos == 0 && A[0] == 0) 

{the above if statement should also include "B!=1" so that if an array(A[1]={0}) is passed as an input with B as 1 and C as 5, it would not return 0

    count--;
}

int result = count * pow(n, B - 1);

if(i == n || A[i] != C[pos]) {
    return result;
}

return result + rec(A, B - 1, C, pos + 1);

}
`

@PrathamMeena
Copy link
Author

I may not have detailed knowledge of coding for now but this was the case I observed and it got solved

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