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

Open
@PrathamMeena

Description

@PrathamMeena

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);

}
`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions