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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T09:28:32+00:00 2026-05-11T09:28:32+00:00

I was just interviewed with a question, and I’m curious what the answer ought

  • 0

I was just interviewed with a question, and I’m curious what the answer ought to be. The problem was, essentially:

Say you have an unsorted list of n integers. How do you find the k minimum values in this list? That is, if you have a list of [10, 11, 24, 12, 13] and are looking for the 2 minimum values, you’d get [10, 11].

I’ve got an O(n*log(k)) solution, and that’s my best, but I’m curious what other people come up with. I’ll refrain from polluting folks brains by posting my solution and will edit it in in a little while.

EDIT #1: For example, a function like: list getMinVals(list &l, int k)

EDIT #2: It looks like it’s a selection algorithm, so I’ll toss in my solution as well; iterating over the list, and using a priority queue to save the minimum values. The spec on the priority queue was that the maximum values would end up at the top of the priority queue, so on comparing the top to an element, the top would get popped and the smaller element would get pushed. This assumed the priority queue had an O(log n) push and an O(1) pop.

  • 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. 2026-05-11T09:28:32+00:00Added an answer on May 11, 2026 at 9:28 am

    This is the quickSelect algorithm. It’s basically a quick sort where you only recurse for one part of the array. Here’s a simple implementation in Python, written for brevity and readability rather than efficiency.

    def quickSelect(data, nLeast) :     pivot = data[-1]     less = [x for x in data if x <= pivot]     greater = [x for x in data if x > pivot]     less.append(pivot)      if len(less) < nLeast :         return less + quickSelect(greater, nLeast - len(less))     elif len(less) == nLeast :         return less     else :         return quickSelect(less, nLeast) 

    This will run in O(N) on average, since at each iteration, you are expected to reduce the size of data by a multiplicative constant. The result will not be sorted. The worst case is O(N^2), but this is dealt with in essentially the same way as a quick sort, using things like median-of-3.

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

Sidebar

Ask A Question

Stats

  • Questions 99k
  • Answers 99k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer your script may be getting inserted into the page before… May 11, 2026 at 7:46 pm
  • Editorial Team
    Editorial Team added an answer The solution is very simple. git checkout <filename> tries to… May 11, 2026 at 7:46 pm
  • Editorial Team
    Editorial Team added an answer Are you sure that log4j is actually using your log4j.xml… May 11, 2026 at 7:46 pm

Related Questions

I was just interviewed with a question, and I'm curious what the answer ought
I was answering some quiz questions for an interview, and the question was about
I was at an interview for a C position in which they presented me
I am working with a survey dataset. It has two string vectors , start
This morning, I was reading Steve Yegge's: When Polymorphism Fails , when I came

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.