Company: Myntra
Difficulty: medium
Squirrel's Food Problem Description You are given the position of N squirrels on a number line and K food packets for feeding these squirrels. Each squirrel must eat from the packet nearest to it such that the sum of the distances traveled by all the squirrels in reaching them is the minimum possible. Your task is to find the optimal positions for all the food packets on the number line and return an integer value representing the minimum distance that needs to be traveled by the squirrels. Note: You can place the packets anywhere on integer points of the number line, including at the positions of squirrels. Examples Example 1: Input: N = 5, K = 2, squirrels = [2,3,5,12,19] Output: 10 Explanation: One of the optimal ways to choose the position of food packets is 3 and 14 where the sum of the distances of all the squirrels is |2-3| + |3-3| + |5-3| + |12-14| + |19-14| = 1 + 0 + 2 + 2 + 5 = 10. Therefore, 10 is returned as the output. Example 2: Input: N = 6, K = 2, squirrels = [1,2,3,4,5