Company: Murf ai_22oct
Difficulty: medium
Longest Subarray Sum Less Than or Equal to K Problem Description Find the length of the longest subarray whose elements sum to a value less than or equal to k. A subarray is defined as a contiguous block of elements from the original array. Function Description Complete the function maxLength in the editor with the following parameter(s): int a[n] : an array of integers int k : the maximum allowable sum Returns: int : the length of the longest subarray of a that sums to a number less than or equal to k . Examples Example 1: Input: a = [1, 2, 3], k = 3 Output: 2 Explanation: All possible subarrays: [1] : sum = 1 (valid, 1 ≤ 3) [2] : sum = 2 (valid, 2 ≤ 3) [3] : sum = 3 (valid, 3 ≤ 3) [1, 2] : sum = 3 (valid, 3 ≤ 3) [2, 3] : sum = 5 (invalid, 5 > 3) [1, 2, 3] : sum = 6 (invalid, 6 > 3) The longest valid subarray is [1, 2] with length 2. Example 2: Input: a = [3, 1, 2, 1], k = 4 Output: 3 Explanation: The subarrays of [3, 1, 2, 1] having elements that sum to a value less