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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:23:03+00:00 2026-06-14T04:23:03+00:00

Possible Duplicate: Can you sort n integers in O(n) amortized complexity? I have to

  • 0

Possible Duplicate:
Can you sort n integers in O(n) amortized complexity?

I have to write an algorithm which, given an unsorted list of integers, returns “the lowest number in the file which exceeds at least 90% of the numbers in the file”, or -1 if no such number exists. Simple enough: I sort the list using merge sort, then start at the index 90% of the way along and look for the first number to be larger than the number before it.

Part 2 of the question has got me stumped though. We’re given some more information: the integers represent salaries, meaning they’re all positive, and the vast majority of them are underneath 1,000,000. Apparently with this extra information it’s possible to write an algorithm that solves the original problem in O(n) time, but I haven’t the slightest clue how this is possible. Any ideas?

I would post what I’ve done so far, but I haven’t been able to come up with anything whatsoever.

  • 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-14T04:23:05+00:00Added an answer on June 14, 2026 at 4:23 am

    You are looking for a selection algorithm, which selects the kth largest element in an array. The Wikipedia article gives an O(n) algorithm to do this which is similar to quicksort, but does not sort the entire array, and thus avoids the O(n*logn) runtime.

    If the elements are all bounded in a certain range (e.g. 1-1000000 in your case), then another approach is to sort them using counting sort or bucket sort in O(n), and then select the element you need. Since in this case the “vast majority” of elements is under 1000000 rather than all of them, you can perform a bucket sort with 1000001 buckets, and use the last bucket for all elements above 1000000.

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

Sidebar

Related Questions

Possible Duplicate: Which sorting algorithm is used by STL’s list::sort()? Which sorting algorithm can
Possible Duplicate: Sort list using stl sort function My question is can we sort
Possible Duplicate: Can I sort two lists in relation to each other? I have
Possible Duplicate: Easiest way to sort DOM nodes? I have a list of DIVs,
Possible Duplicate: Can I scroll a ScrollView programmatically in Android? I have a chat
Possible Duplicate: Can Read-Only Properties be Implemented in Pure JavaScript? I have an Object
Possible Duplicate: Sort multidimensional Array by Value (2) How can i sort array by
Possible Duplicate: Sort ArrayList of custom Objects by property I have an arrayList of
Possible Duplicate: Python analog of natsort function (sort a list using a “natural order”
Possible Duplicate: Sort by key of dictionary inside a dictionary in Python I have

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.