Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

Game of two stack c#

public static int twoStacks(int maxSum, List<int> a, List<int> b)
{
    int i =0;
    int sum =0;
    while(a.Count>i && sum + a[i]<= maxSum)
    {
        sum+=a[i++];
    }
    var count = i;
    var j = 0;
    while(j<b.Count && i>=0)
    {  
        sum+=b[j++];
        while(sum > maxSum && i>0)
        {
            sum-=a[--i];
        }
        if(sum<=maxSum && i+j>count)
            count=i+j;
    }
    return count;
}
 
PREVIOUS NEXT
Tagged: #Game #stack
ADD COMMENT
Topic
Name
2+8 =