Minimize Travel Distance to Collect K Objects on X-Axis
N objects are placed on X-axis, and coordinates are given. Starting your journey with coordinate 0, find minimum distance you need to travel to collect K objects (If multiple objects are placed on same position, you may collect some or all of them). Examples: Input: arr[] = {10, -10, -30, 20, 50}, K = 3 Output: 40 Explanation:… Read More »
