Problem statement

https://binarysearch.com/problems/K-Prefix/

Solution

Just evaluate prefix sums and iterate it.

Complexity

It is O(n) for time and space.

Code

class Solution:
    def solve(self, nums, k):
        acc = [0] + list(accumulate(nums))
        ans = 0
        for i in range(len(acc)):
            if acc[i] <= k:
                ans = i
        return ans - 1