Capgemini OA Question 2024 May | Arrays | on-campus
Question · Posted Jun 2026
Question: Maximum Subarray Problem Statement Given an integer array nums, find the subarray with the largest sum, and return its sum. Constraints 1 <= nums.length <= 105 -104 <= nums[i] <= 104 Examples Example 1: Input: nums = [-2,1,-3,4,-1,2,1,-5,4] Output: 6 Explanation 1: The subarray [4,-1,2,1] has the largest sum = 6. At index 3 (value=4), we start a new subarray. Adding -1, 2, 1 keeps the running sum positive at 6. Adding -5 drops it to 1, so the ...
The full answer & interview discussion are available to premium members.
Log in Create a free account