Maximum sum of subarrays having distinct elements of length K
Improve Article
Save Article
Like Article
Improve Article
Save Article
Given an array, arr and a value k, represent the length of the subarray to be considered. Find the maximum sum that can be obtained from the subarray of length k such that each element of the subarray is unique. If there is no subarray that meets the required condition then return 0.Examples:Input: arr = {1, 5, 4, 2, 9, 9, 9}, k = 3Output: 15Explanation: The possible subarrays of arr with length 3 are:{1, 5, 4} which meets the requirements and has…