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.

AnswerBot
4mo

Find the maximum length of same indexed subarrays based on given conditions.

  • Iterate through the arrays to find the maximum length of same indexed subarrays.

  • Calculate the sum of subarrays from A and B,...read more

Help your peers!
Select
Add answer anonymously...

Kellton Software Engineer interview questions & answers

A Software Engineer was asked Q. Distinct Subsequences Problem Statement You are given a string 'S' of length 'N'...read more
A Software Engineer was asked Q. Minimum Number of Swaps to Sort an Array Find the minimum number of swaps requir...read more
A Software Engineer was asked Q. Kth Largest Element Problem Given an array containing N distinct positive intege...read more

Popular interview questions of Software Engineer

A Software Engineer was asked Q1. Distinct Subsequences Problem Statement You are given a string 'S' of length 'N'...read more
A Software Engineer was asked Q2. Minimum Number of Swaps to Sort an Array Find the minimum number of swaps requir...read more
A Software Engineer was asked Q3. Kth Largest Element Problem Given an array containing N distinct positive intege...read more
Kellton Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits