Optimizing Resource Allocation

An array of size n represents a set of available resources. Identify a subarray that optimally utilizes these resources under the following constraints:

  • The subarray must have a specific length, denoted as k.
  • All elements in the subarray must be unique, representing distinct resource allocations.

The ultimate goal is to find the subarray that maximizes the sum of the allocated resources. Return the sum for that subarray. If it is not possible to allocate resources per the constraints, return -1.

Note: A subarray is a contiguous segment of an array.

Function Description

Complete the function findOptimalResources in the editor.

Example

Unlock to view complete problem details

and practice with sample input/output

Was this article helpful?

View Test Cases & Run Code requires membership

Input Variables
Execution Result: