Company: Publicis Sapient_27sept
Difficulty: medium
Maximum Profit Subarray with Length Constraint Problem Description You need to analyze the performance of investments in a stock. The profit and loss (P&L) for each month are provided, where each value indicates the profit earned (positive value) or loss incurred (negative value) in that month. Your task is to find the maximum net profit that can be gained from any contiguous segment of months, with the constraint that the segment cannot exceed a given number of months k. Examples Example 1: n = 6 pnl = [3, -2, 2, 8] k = 4 Explanation: The optimal subarray is [3, -2, 2, 8] with a total profit of 3 + (-2) + 2 + 8 = 11 . While the subarray [4, 3, -2, 7] has a higher profit of 12, its length exceeds the constraint k=4. The answer is 8. Function Description Complete the function getMaxProfit below. The function is expected to return a LONG_INTEGER . The function accepts the following parameters: 1. INTEGER pnl_count 2. INTEGER_ARRAY pnl 3. INTEGER k long getMaxProfit(int pnl_count, int* pn