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 6760579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:04:50+00:00 2026-05-26T14:04:50+00:00

I encountered this problem while preparing for my exams. Given two arrays of numbers

  • 0

I encountered this problem while preparing for my exams.

Given two arrays of numbers a1,…, an and b1,….,bn where each number is 0 or 1, the fastest algorithm to find the largest span (i,j) such that , ai + ai+1 +….+aj = bi + bi+1 +….+bj or report that there is not such span.

(A) Takes O(3^n) and omega(2^n) time if hashing is permitted.

(B) Takes O(n^3) and omega(n^2.5) and time in the key comparison mode

(C)Takes theta(n) time and space

(D)Takes O(square-root(n)) time only if the sum of 2n elements is an even number.

  • 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-26T14:04:50+00:00Added an answer on May 26, 2026 at 2:04 pm

    The only solution I can think of has O(n^2) and omega(n) time if anybody bothers to do the right check. It could probably be improved if anybody manages to find a way to take advantage of all values being 0 and 1.

    int[] a = { 1, 1, 0, 1, 1, 0, 1, 0, 1 };
    int[] b = { 0, 1, 0, 0, 1, 1, 0, 1, 0 };
    
    int lastSum = 0; int lastI = 0; int lastJ = 0;
    int sumA = 0; int sumB = 0; 
    for(int i = 0; i < a.Length; i++) // start the sum at [i].
    {
        sumA = a[i]; sumB = b[i];
        for (int j = i + 1; j < a.Length; j++) // summing ends on [j]
        //do
        {
            if (sumA == sumB && (lastJ - lastI < j - i))
            {
                lastSum = sumA;
                lastI = i; lastJ = j;
                if (j == a.Length - 1) // you will never find a bigger interval.
                {
                    Console.Out.WriteLine("(i, j) = (" + lastI + ", " + lastJ + ")");
                    return;
                }
            }
            sumA += a[j];
            sumB += b[j];
        }
    }
    Console.Out.WriteLine("(i, j) = (" + lastI + ", " + lastJ + ")");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've encountered this problem (while trying to add SQL Server Database (.mdf) file to
I encountered this problem while solving a practice test Consider the following code written
I encountered this problem while solving a practice test Consider this C code to
While I was learning kohana and making single article, i encountered this problem. I
While converting an old code, I encountered the following problem. Given an HTML string,
Hi i encountered this problem whereby when i initialized my String[], there seems to
Uhm I'm not sure if anyone has encountered this problem a brief description is
Making my first steps in RIA Services (VS2010Beta2) and i encountered this problem: created
Has anyone encountered this oddity? I'm checking for the existence of a number of
I've encountered this issue on two different machines and can't figure out what the

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.