FastPrepMaximum Size Subarray Sum Equals K
Problems/Maximum Size Subarray Sum Equals K

Maximum Size Subarray Sum Equals K

eBay logoeBay● MediumFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: The interview report establishes the task identity and central capability. This practice contract supplies only the portable interface, deterministic boundary rules, and output serialization needed for consistent execution.

Given an integer array nums and an integer k, return the maximum length of a contiguous nonempty subarray whose elements sum to k.

Return 0 if no such subarray exists.

Function

maxSubArrayLen(nums: int[], k: int) → int

Examples

Example 1

nums = [1,-1,5,-2,3]k = 3return = 4

The subarray [1,-1,5,-2] sums to 3.

Example 2

nums = [-2,-1,2,1]k = 1return = 2

The subarray [-1,2] has length 2 and sum 1.

Constraints

  • 1 <= nums.length <= 2 * 10^5.
  • Values and prefix sums fit in a 64-bit signed integer.

More eBay problems

  • Meeting Rooms IIPHONE SCREEN · Seen Oct 2026
  • Count Staircases with Strictly Increasing StepsONSITE INTERVIEW · Seen Oct 2026
  • Hierarchical Permission CheckONSITE INTERVIEW · Seen Oct 2026
All eBay interview questionsSee eBay hiring insights
Saved
class Solution {
    public int maxSubArrayLen(int[] nums, int k) {
      // write your code here
    }
}
Checking account…