Count highest element sequnce for the digit 1 in Arraylist in C#

Count highest element sequnce for the digit 1 in Arraylist in C#


using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Algorithm
{
    class Program
    {

        ArrayList arr = new ArrayList() {1,0,0,0,1,1,1,0,0,0,0,0,1,1};
        List<object> n = new List<object>();
        public void Arrcheck()
        {
            foreach (var i in arr)
            {
                n.Add(i);
            }
            var a = "";
            for (int i = 0; i < n.Count(); i++)
            {
               
                if ((int)n[i] == 0)
                {
                    a += " ";                   
                }
                else if((int)n[i] == 1)
                {
                    a += n[i] + "";
                }
               
                   
               

            }

            var jsplit = a.Split(' ');
            List<count> l = new List<count>();
            foreach (var j in jsplit)
            {
                if(j.Length >0)
                Console.Write(j+"  "+ j.Length+"\n");
            }
           
         
                 
        }
        static void Main(string[] args)
        {
            Program p = new Program();
            p.Arrcheck();
            Console.Read();
        }
    }
}

Output:-

1     1
111  3
11    2

Share this

Previous
Next Post »