Welcome to the third PHP coding puzzle !
You are given an array of integers, and you need to write a PHP function that will find the largest sum of any contiguous subarray in the array. A subarray is a contiguous subset of the array.
For example, given the array [1, -2, 3, 10, -4, 7, 2, -5], the contiguous subarray with the largest sum is [3, 10, -4, 7, 2], and the sum of that subarray is 18.
Here’s the function signature:
function maxSubArray($nums) {
// Your code here
}
You can assume that the input array is non-empty.
The solution is already available in the next page 😉 Feel free to share with us your solution here in comments or Github.