Search
 
SCRIPT & CODE EXAMPLE
 

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;
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: c sharp Enum class 
Csharp :: c# arithmetic operators 
Csharp :: set field in list linq 
Csharp :: how to get odd saturday in a month in c# 
Csharp :: ASP.MVC display image from SqlServer 
Csharp :: Diplay player final score in new scene in unity 
Csharp :: .net core executenonqueryasync transaction 
Csharp :: C# return json data from File 
Csharp :: unity number generator 
Csharp :: simplified if statement c# 
Csharp :: httprequestmessage with authorization .net 5 
Csharp :: c# wtssendmessage 
Csharp :: sterge element din coada c# 
Csharp :: Filter list contents with predicate (Lambda) 
Csharp :: c# unzip all archive files inside directory 
Csharp :: using mediamanager how to play mp3 files 
Csharp :: List picking records from database 
Csharp :: nullable 
Csharp :: unity manager.instance 
Csharp :: afaik 
Csharp :: c# switch expression 8.0 
Csharp :: id dublication exception c# .net core 
Csharp :: C# replace all . except last one 
Csharp :: binary search tree c# stackoverflow 
Csharp :: Options Pattern how to use 
Csharp :: c# isalphanumeric 
Csharp :: bunifu form fade transition c# 
Csharp :: set data annotation in model c# 
Csharp :: TTTTTTTTTTTTTTTTTTTTESTTT 
Csharp :: C# is folder 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =