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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:18:21+00:00 2026-05-16T22:18:21+00:00

Given an array with N elements. We know that one of those elements repeats

  • 0

Given an array with N elements. We know that one of those elements repeats itself at least N/2 times.

We don’t know anything about the other elements . They may repeat or may be unique .

Is there a way to find out the element that repeats at least N/2 times in a single pass or may be O(N)?

No extra space is to be used .

  • 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-16T22:18:21+00:00Added an answer on May 16, 2026 at 10:18 pm

    st0le answered the question, but here’s a 5minute implementation:

    #include <stdio.h>
    
    #define SIZE 13
    
    int boyerMoore(int arr[]) {
        int current_candidate = arr[0], counter = 0, i;
        for (i = 0; i < SIZE; ++i) {
            if (current_candidate == arr[i]) {
                ++counter;
                printf("candidate: %i, counter: %i\n",current_candidate,counter);
            } else if (counter == 0) {
                current_candidate = arr[i];
                ++counter;
                printf("candidate: %i, counter: %i\n",current_candidate,counter);
            } else {
                --counter;
                printf("candidate: %i, counter: %i\n",current_candidate,counter);
            }
        }
        return current_candidate;
    }
    
    int main() {
        int numbers[SIZE] = {5,5,5,3,3,1,1,3,3,3,1,3,3};
        printf("majority: %i\n", boyerMoore(numbers));
        return 0;
    }
    

    And here’s a fun explanation (more fun than reading the paper, at least): http://userweb.cs.utexas.edu/~moore/best-ideas/mjrty/index.html

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

Sidebar

Related Questions

Design an algorithm that, given a list of n elements in an array, finds
Suppose that you're given an array A of n distinct elements drawn from some
Given an array. How can we find sum of elements in index interval (i,
Summary: Given an array {a, b, ..., w, x, ..., z} insert several elements
Given an array A with n integers. In one turn one can apply the
The original problem statement is this one: Given an array of 32bit unsigned integers
I know that given enough time I'll figure this out, but it sure would
This problem is taken from interviewstreet.com Given array of integers Y=y1,...,yn, we have n
given an array: array = [16 16 16 22 23 23 23 25 52
Given an Array A of n subArrays Sn, how can I select the Array

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.