Max Length of Same Indexed Subarrays Problem
Given two integer arrays A
and B
, and an integer C
, the goal is to determine the maximum possible length K
of the same indexed subarrays. The condition is that the sum of the maximum element in the K-length subarray from B
plus the product of K
and the sum of the K-length subarray from A
does not exceed C
.
Example:
Input:
N = 6
C = 23
A[] = {5, 19, 13, 2, 4, 0}
B[] = {10, 4, 7, 4, 5, 14}
Output:
2
Explanation:
Considering the subarray from index 3 to 4 (0-based index), the subarray sum of A
= 6, and the maximum element in B
= 5. So, 6*2 + 5 = 17, which is less than 23. Thus, the maximum length is 2.
Constraints:
- 1 <= T <= 10
- 1 <= N <= 5000
- 0 <= ARR[i] <= 106
Note:
You do not need to print the output. Return the computed result.
Be the first one to answer
Add answer anonymously...
Top Kellton Software Engineer interview questions & answers
Popular interview questions of Software Engineer
Top HR questions asked in Kellton Software Engineer
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app