Flip

CSharp · Console

/Program.cs

using System;
					
public class Program
{
	static int max = 0;
	static int temp = 0;
	static bool flip = false;
	static int recent = 0;
	
	public static void Main()
	{

		var input = new int[1,1,0,0,1,1,1,1,0,1,1,1,0,1,1,1,1,1,1,1,1,1];
		foreach (var x in input){
			Console.WriteLine(temp);
			if(x == 1){
				temp += 1;
				CompareAndAssign();
			}
			else{
				if(!flip)
				{
					flip = true;
					temp += 1;
					recent += 1;
					CompareAndAssign();
				}
				else
				{
					temp = recent;
					recent = 0;
					temp += 1;
					CompareAndAssign();
				}
			}
		};
		Console.WriteLine(max);
	}

	public static void CompareAndAssign(){
		if(temp >= max)
		{
			max = temp;
		}
	}
}
;