Skip to content

Practice Maximum Tastiness of Candy Basket

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#2517
LeetCode Problem

Maximum Tastiness of Candy Basket

Problem Statement

You are given an array of positive integers price where price[i] denotes the price of the ith candy and a positive integer k. The store sells baskets of k distinct candies. The tastiness of a candy basket is the smallest absolute difference of the prices of any two candies in the basket. Return the maximum tastiness of a candy basket.

Source: Maximum Tastiness of Candy Basket on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
price = [13,5,1,8,21,2], k = 3
Output
8

# Example 2

Input
price = [1,3,1], k = 2
Output
2

# Example 3

Input
price = [7,7,7,7], k = 2
Output
0

Constraints

2 <= k <= price.length <= 10^5
1 <= price[i] <= 10^9

Related LeetCode Problems

Practice more problems similar to Maximum Tastiness of Candy Basket.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.