
Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
The answer is binary searchable.
For some x, we can use a greedy strategy to check if it is possible to pick k distinct candies with tastiness being at least x.
Sort prices and iterate from left to right. For some price[i] check if the price difference between the last taken candy and price[i] is at least x. If so, add the candy i to the basket.
So, a candy basket with tastiness x can be achieved if the basket size is bigger than or equal to k.