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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:39:43+00:00 2026-06-04T03:39:43+00:00

This question was asked to me in an interview. Given an unsorted list of

  • 0

This question was asked to me in an interview. Given an unsorted list of integers if one can find all occurrences of the max value in linear time and constant memory.

I couldn’t answer it back then and came across the median of medians algorithm. Still unsure if this algorithm is applicable in this case.

  • 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-04T03:39:45+00:00Added an answer on June 4, 2026 at 3:39 am

    You can find a max value of a set in O(n). Just go through the list and update the max:

    max = int_array[0]
    for i = 1 to int_array.size():
        if int_array[i] > max:
            max = int_array[i]
    

    In the next pass, you can call the desired functionality on every such element. E.g. if you want to print out their position, and finally their count:

    count = 0
    for i = 0 to int_array.size():
        if int_array[i] == max:
            print "Index i"
            count += 1
    print count
    

    You can always determine the count in the first pass, increasing it whenever the current element is equal to max and resetting it to one every time you change the current max (e.g. current element is larger than the current max). In the same way, you could remember the positions of the maximums in the first pass. So, integrating it all to one:

    count = 1
    max = int_array[0]
    indexes = [0]
    for i = 1 to int_array.size():
        if int_array[i] == max:
            count += 1
            indexes.insert(i)
        else if int_array[i] > max:
            count = 1
            indexes = [i]
            max = int_array[i]
    print "There are " + count + " elements with maximal value of " + max
    print "On positions: "
    for int i = 0 to count:
        print indexes[i]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This was the question asked in interview. Can we call one constructor from another
I was asked this question during phone interview. Given two strings find the minimal
Recently in a job interview I was asked this following question (for Java): Given:
One of my friend was asked this question in an interview - You have
This question was asked of me in an interview. How can we convert a
This question was asked at interview. Say I have a contract. [ServiceContract] public interface
This question was asked to me in an interview. Suppose char *p=malloc(n) assigns more
This is an interview question asked a month ago.... Do session use cookies? If
I was asked this question in a job interview, and I'd like to know
Yesterday in my interview I was asked this question. (At that time I was

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.