java.lang.Object
g2501_2600.s2517_maximum_tastiness_of_candy_basket.Solution

public class Solution extends Object
2517 - Maximum Tastiness of Candy Basket.<p>Medium</p> <p>You are given an array of positive integers <code>price</code> where <code>price[i]</code> denotes the price of the <code>i<sup>th</sup></code> candy and a positive integer <code>k</code>.</p> <p>The store sells baskets of <code>k</code> <strong>distinct</strong> candies. The <strong>tastiness</strong> of a candy basket is the smallest absolute difference of the <strong>prices</strong> of any two candies in the basket.</p> <p>Return <em>the <strong>maximum</strong> tastiness of a candy basket.</em></p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> price = [13,5,1,8,21,2], k = 3</p> <p><strong>Output:</strong> 8</p> <p><strong>Explanation:</strong> Choose the candies with the prices [13,5,21].</p> <p>The tastiness of the candy basket is: min(|13 - 5|, |13 - 21|, |5 - 21|) = min(8, 8, 16) = 8.</p> <p>It can be proven that 8 is the maximum tastiness that can be achieved.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> price = [1,3,1], k = 2</p> <p><strong>Output:</strong> 2</p> <p><strong>Explanation:</strong> Choose the candies with the prices [1,3].</p> <p>The tastiness of the candy basket is: min(|1 - 3|) = min(2) = 2.</p> <p>It can be proven that 2 is the maximum tastiness that can be achieved.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> price = [7,7,7,7], k = 2</p> <p><strong>Output:</strong> 0</p> <p><strong>Explanation:</strong> Choosing any two distinct candies from the candies we have will result in a tastiness of 0.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>2 <= k <= price.length <= 10<sup>5</sup></code></li> <li><code>1 <= price[i] <= 10<sup>9</sup></code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • maximumTastiness

      public int maximumTastiness(int[] price, int k)