Tap here to switch tabs
Problem
Submissions

Problem: Minimum Cost of Buying Candies With Discount

Minimum Cost of Buying Candies With Discount gives an array of candy prices. Return the least cost to buy all candies when each free candy costs no more than the cheaper of the two paid candies.

Statement

A shop is offering a special discount on candies. For every 22 candies purchased at their regular prices, you can choose a 33rd candy to take for free. The cost of the free candy must be less than or equal to the minimum cost of the 22 purchased candies.

You are given an integer array cost, where cost[i] denotes the price of the candy at index i. Return the minimum total cost required to acquire all candies.

Constraints:

  • 1≤1 \leq cost.length ≤100\leq 100

  • 1≤1 \leq cost[i] ≤100\leq 100

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Cost of Buying Candies With Discount

Minimum Cost of Buying Candies With Discount gives an array of candy prices. Return the least cost to buy all candies when each free candy costs no more than the cheaper of the two paid candies.

Statement

A shop is offering a special discount on candies. For every 22 candies purchased at their regular prices, you can choose a 33rd candy to take for free. The cost of the free candy must be less than or equal to the minimum cost of the 22 purchased candies.

You are given an integer array cost, where cost[i] denotes the price of the candy at index i. Return the minimum total cost required to acquire all candies.

Constraints:

  • 1≤1 \leq cost.length ≤100\leq 100

  • 1≤1 \leq cost[i] ≤100\leq 100