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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:03:06+00:00 2026-06-11T11:03:06+00:00

Yet another interview question asked me to find the maximum possible subarray of repeated

  • 0

Yet another interview question asked me to find the maximum possible subarray of repeated values given a sorted array in shortest computational time possible.

Let input array be A[1 ... n]
Find an array B of consecutive integers in A such that:
for x in range(len(B)-1):
     B[x] == B[x+1]

I believe that the best algorithm is dividing the array in half and going from the middle outwards and comparing from the middle the integers with one another and finding the longest strain of the same integers from the middle. Then I would call the method recursively by dividing the array in half and calling the method on the two halves.

My interviewer said my algorithm is good but my analysis that the algorithm is O(logn) is incorrect but never got around to telling me what the correct answer is. My first question is what is the Big-O analysis of this algorithm? (Show as much work as possible please! Big-O is not my forte.) And my second question is purely for my curiosity whether there is an even more time efficient algorithm?

  • 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-06-11T11:03:08+00:00Added an answer on June 11, 2026 at 11:03 am

    The best you can do for this problem is an O(n) solution, so your algorithm cannot possibly be both correct and O(lg n).

    Consider for example, the case where the array contains no repeated elements. To determine this, one needs to examine every element, and examining every element is O(n).

    This is a simple algorithm that will find the longest subsequence of a repeated element:

    start = end = 0
    maxLength = 0
    i = 0
    while i + maxLength < a.length:
        if a[i] == a[i + maxLength]:
            while i + maxLength < a.length and a[i] == a[i + maxLength]:
                maxLength += 1
            start = i
            end = i + maxLength
        i += maxLength
    
    return a[start:end]
    

    If you have reason to believe the subsequence will be long, you can set the initial value of maxLength to some heuristically selected value to speed things along, and then only look for shorter sequences if you don’t find one (i.e. you end up with end == 0 after the first pass.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So Yet another SMS question :-) I researched, but could not find a solution
Yet another PHP question. I've got two arrays: one string-based and the other numeric.
yet another PHP question which I am stuck on, so here is what im
Yet another Scrabble project question... This is a simple one. It seems I am
yet another basic question ... I have an app that takes about 4-5 secs
Yet another SVN guideline question, I know. I recently joined a new company which
I apologize for yet another __init__.py question. I have the following package structure: +contrib
I have (yet another) powershell query. I have an array in powershell which i
Yet another question, go me!... Anyway, I have 2 classes with private constructors and
Yet another IE is doing something different from other browsers question but this is

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.