Tap here to switch tabs
Problem
Submissions

Problem: Maximum Tastiness of Candy Basket

med
30 min
Try to solve the Maximum Tastiness of Candy Basket problem.

Statement

You are given an array of positive integers price, where each element represents the price of a candy, and an integer k.

A candy basket contains k distinct candies chosen from price. The tastiness of a candy basket is defined as the minimum absolute difference between the prices of any pair of candies in the basket.

Return the maximum tastiness that can be achieved for a basket containing k candies.

Constraints:

  • 2≤2 \leq k ≤\leq price.length ≤105\leq 10^5

  • 1≤1 \leq price[i] ≤109\leq 10^9

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Maximum Tastiness of Candy Basket

med
30 min
Try to solve the Maximum Tastiness of Candy Basket problem.

Statement

You are given an array of positive integers price, where each element represents the price of a candy, and an integer k.

A candy basket contains k distinct candies chosen from price. The tastiness of a candy basket is defined as the minimum absolute difference between the prices of any pair of candies in the basket.

Return the maximum tastiness that can be achieved for a basket containing k candies.

Constraints:

  • 2≤2 \leq k ≤\leq price.length ≤105\leq 10^5

  • 1≤1 \leq price[i] ≤109\leq 10^9