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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T01:05:12+00:00 2026-06-19T01:05:12+00:00

I have read this problem Find the most common entry in an array and

  • 0

I have read this problem
Find the most common entry in an array

and the answer from jon skeet is just mind blowing .. 🙂

Now I am trying to solve this problem find an element which occurs more than n/3 times in an array ..

I am pretty sure that we cannot apply the same method because there can be 2 such elements which will occur more than n/3 times and that gives false alarm of the count ..so is there any way we can tweak around jon skeet’s answer to work for this ..?

Or is there any solution that will run in linear time ?

  • 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-19T01:05:13+00:00Added an answer on June 19, 2026 at 1:05 am

    Jan Dvorak’s answer is probably best:

    • Start with two empty candidate slots and two counters set to 0.
    • for each item:
      • if it is equal to either candidate, increment the corresponding count
      • else if there is an empty slot (i.e. a slot with count 0), put it in that slot and set the count to 1
      • else reduce both counters by 1

    At the end, make a second pass over the array to check whether the candidates really do have the required count. This isn’t allowed by the question you link to but I don’t see how to avoid it for this modified version. If there is a value that occurs more than n/3 times then it will be in a slot, but you don’t know which one it is.

    If this modified version of the question guaranteed that there were two values with more than n/3 elements (in general, k-1 values with more than n/k) then we wouldn’t need the second pass. But when the original question has k=2 and 1 guaranteed majority there’s no way to know whether we “should” generalize it as guaranteeing 1 such element or guaranteeing k-1. The stronger the guarantee, the easier the problem.

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

Sidebar

Related Questions

I have read all threads about this without finding any answer to my problem.
I have read a lot of related topics here regarding this problem but I
I have read the other threads regarding this same problem but I still don't
This is my homework, but please read my problem description first. I have to
I have read this question and the simple and clear answer but it's not
I have read this article from High Scalability about Stack Overflow and other large
I have read a few posts on this but I could not find help
Ok I seem to have got the most of the problem solved, I just
This is probably not a dup; I have read through many similar problems on
I have read this thread when I got the the git: command not found

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.