Problem Submissions Solution

Shop in Candy Store

Difficulty: Easy

Acceptance: %

Points: 20.00

In a candy store, there are n different types of candies available and the prices of all the N different types of candies are provided to you. You are now provided with an attractive offer.

For every candy you buy from the store and get K other candies ( all are different types ) for free. Now you have to answer two questions. Firstly, you have to find what is the minimum amount of money you have to spend to buy all the n different candies. Secondly, you have to find what is the maximum amount of money you have to spend to buy all the n different candies.

In both the cases you must utilize the offer i.e. you buy one candy and get k other candies for free.

Topics

Companies

Articles

Examples:

Expected Time Complexity: O(n log n)

Expected Auxiliary Space: O(1)

Constraints:
  • 1 <= n <= 100000
  • 0 <= k <= N-1
  • 1 <= candies[i] <= 10000
Companies:
Amazon Microsoft Walmart
Topics:
Sorting Algorithms
Locked Content
Access Restricted: Please Login to access the code editor and test cases.