Company: JPMC Fte_30march
Difficulty: medium
You are given an array arr of size n , where each element represents an available resource. Your task is to identify a subarray that meets the following conditions: The subarray must have a length of exactly k All elements in the subarray must be unique, representing distinct resource allocations Among all such valid subarrays: Compute the sum of the elements Return the maximum sum possible If no subarray satisfies these conditions, return -1. Note: A subarray is a contiguous segment of an array. Example Suppose n = 5, k = 3, and arr = [1, 2, 3, 7, 3, 5] Output: 15 The following are the subarrays of length k = 3, and all elements are distinct: [1, 2, 3], and 1 + 2 + 3 = 6 [2, 3, 7], sum = 12 [7, 3, 5], sum = 15 Function Description Complete the function findOptimalResources in the editor below. findOptimalResources has the following parameter(s): int arr[n] : the set of available resources int k : the size of the subarray Returns long: maximum sum of any subarray that meets the criteri