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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:49:24+00:00 2026-06-17T12:49:24+00:00

Given a list of n objects, write a function that outputs the minimum set

  • 0

Given a list of n objects, write a function that outputs the minimum set of numbers that sum to at least K. FOLLOW UP: can you beat O(n ln n)?

The minimum set will be a set with 1 element. Don’t we just have to traverse the array and find an element i.e. >= K.

Otherwise for O(nlgn), I understand we have to first sort the array and then we can find pair or triplets which sum >=k.
What if we don’t find such a combination and have to go for bigger sets won’t this problem be same as N sum problem?

  • 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-17T12:49:25+00:00Added an answer on June 17, 2026 at 12:49 pm

    Here’s a linear algorithm that uses linear-time median finding as a subroutine:

    Findsum(A, K) {
      Let n be the length of A.
      Let M be the median element of A, found in linear time.
      Let L be the elements of A less than M.
      Let U be the elements of A greater than M.
      Let E be the elements of A equal to M.
      If the sum of the elements in U is at least K,
        Return Findsum(U, K).
      Else, if the sum of the elements in U and E is at least K,
        Return U together with enough elements of E that the sum is at least K.
      Else,
        Return Findsum(L, K - sum(U) - sum(E)).
    }
    

    Each recursive call is done on a list at most half the size of A and all other steps take at most linear time, so this algorithm takes linear time overall.

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

Sidebar

Related Questions

I want to get a list of objects from the database between a given
Given the code below, how do I compare a List of objects's values with
Given std::vector<CMyClass> objects; CMyClass list[MAX_OBJECT_COUNT]; Is it wise to do this? for(unsigned int i
I'm attempting to write a Python function to send an email to a list
I am trying to write a generic function that generates an Xelement based on
Given the following view : def comments(request): comments_list = Thing.objects.filter(thing_type=2) #Thing model extends MPTTModel
I am writing common functions to serialize the given object and List<object> as follows
How do I list available methods on a given object or package in Perl?
Given an R list, I wish to find the index of a given list
The original code was somehow complex, i simplify it as: Given: list of class

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.