• + 0 comments

    This code will timeout

    public static string fairRations(List B) { int count=0;
    bool found=false;

        do{ 
    
            found=false;
    
            if(B.Count < 2 || (B.Count == 2 && (B[0]%2 != B[1]%2)))
            {
                break;
            }
    
            for(int i=0; i<B.Count; i++)
            {
                if(B[i]%2 != 0)
                {
                    found=true;
    
                    B[i]+=1;
    
                    if(i+1 < B.Count)
                    {
                        B[i+1]+=1;
                    }
                    else if(i-1 >=0)
                    {
                        B[i-1]+=1;
                    }
    
                    count+=2;
    
                    break;
                }                
            }
    
        }while(found);
    
        return count>0?count.ToString():"NO";
    }
    

    }