Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 802617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T23:38:01+00:00 2026-05-14T23:38:01+00:00

I have a 1-dimensional array that fills up a table of 40 random elements

  • 0

I have a 1-dimensional array that fills up a table of 40 random elements (all the values are either 0 or 1). I want to find the longest consecutive span of values.

For example:

In 111100101 the longest row would be 1111 because it has four consecutive values of 1.

In 011100 the result is 111.

I have no idea how to check upon the “next element” and check if it’s a 0 or 1.
Like the first would be 1111 (count 4) but the next would be a 0 value, meaning I have to stop counting.

My idea was placing this value (4) in a other array (example: 111100101), and place the value of the 1’s back on zero. And start the process all over again.

To find the largest value I have made another method that checks up the biggest value in the array that keeps track of the count of 0’s 1’s, this is not the problem.

But I cannot find a way to fill the array tabelLdr up, having all the values of the group of elements of the same kind (being 0 or 1).

In the code below I have 2 if’s and of course it will never go into the second if (to check if the next value in the array is != to its current state (being 0 or 1).

public void BerekenDeelrij(byte[] tabel, byte[] tabelLdr) 
{
    byte LdrNul = 0, Ldréén = 0;
    //byte teller = 0;

    for (byte i = 0; i < tabel.Length; i++) 
    {
        if (tabel[i] == 0) 
        {
            LdrNul++;
            //this 2nd if cleary does not work, but i have no idea how to implend this sort of idea in my program.
            if (tabel[i] == 1) //if value != 0 then the total value gets put in the second array tabelLdr, 
            {
                tabelLdr[i] = LdrNul;
                LdrNul = 0
            }
        }

        if (tabel[i] == 1)
        {
            Ldréén++;
            if (tabel[i] == 0)
            {
                tabelLdr[i] = Ldréén;
                Ldréén = 0;
            }
        }

    }/*for*/
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T23:38:02+00:00Added an answer on May 14, 2026 at 11:38 pm

    This method should do what you need:

    public int LargestSequence(byte[] array) {
      byte? last = null;
      int count = 0;
      int largest = 0;
      foreach (byte b in array) {
        if (last == b)
          ++count;
        else {
          largest = Math.Max(largest, count);
          last = b;
          count = 1;
        }
      }
      return Math.Max(largest, count);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 545k
  • Answers 545k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • added an answer Well, start off by thinking of which bits of data… May 17, 2026 at 9:17 am
  • added an answer For this task it is a good idea to use… May 17, 2026 at 9:15 am
  • added an answer This is exactly how the Skyhook database (built into many… May 17, 2026 at 9:15 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.