The task is to write an algorithm that takes two parameters. The first parameter is an array of integers (a), the second is an integer (k). You are asked to return the length of the longest subarray within a, such that the sum of its elements is less than or equal to k.
Sigiloso
There is a very inefficient but straightforward solution to this problem. We can iterate through the array, taking the sum at each iteration. If sum ≤ k then we keep going. Whenever we exceed k we store the max size, remove the first element of the array and repeat the process.