Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

Tricky Subset Problem

int isPossible(long long S, long long N, long long X, long long A[])
    {
        // code here
        long long sum = S;
        long long idx = N-1 ;
        for(long long i=0; i<N ;i++)
        {
            A[i]= A[i] + sum;
            sum = sum +  A[i];
            if(A[i] >= X)
            {
                idx=i;
                break;
            }
        }
        while(idx>=0)
        {
            if(X >= A[idx])
            X = X - A[idx];
            idx--;
        }
        if( X==0 || X == S) return 1;
        return 0;
    
    }
Source by practice.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #Tricky #Subset #Problem
ADD COMMENT
Topic
Name
1+7 =