Python solution for this permutaional problem


#1

class Solution:
def solve(self, A, B, C):

    A=list(set(A))
    A.sort()
    count=0
    c=str(C)
    k=0
    if len(A)==0:
        return count
    elif len(c)>B:
        if A[0]==0 and B==1:
            return pow(len(A),B)
        if A[0]==0 and B>1:
            return pow(len(A),B-1)*pow(len(A)-1,1)
        if A[0]==0 and len(A)==1:
            return 1
        return pow(len(A),B)
    elif len(c)==B:
        if B==1:
            for i in range(0,len(A)):
                if(A[i]<int(c)):
                    count=count+1
        else:
            for i in range(0,B):
                flag=1
                for j in range(0,len(A)):
                    if i==0 and A[j]!=0:
                        if A[j]<int(c[i]):
                            count=count+pow(len(A),(B-i-1))
                        if A[j]==int(c[i]):
                            flag=0
                        
                    elif i==B-1:
                        if A[j]<int(c[i]):
                            count=count+1;
                    elif i!=0:
                        if A[j]<int(c[i]):
                            count=count+pow(len(A),(B-i-1))
                        if A[j]==int(c[i]):
                            flag=0;
                if count==0 and flag==1:
                    break
                if flag==1 and count>0:
                    break
                
    
        
    return count

#2

Completely useless and time killing solution.


#3

I think count check at end is not required.Just checking if flag==1 will suffice.