Tag Info

New answers tagged

1

What about this? We run through the array, computing the sums of all the prefixes along the way. (O(n) since we can keep a running tally of the sum) We save the sums we encounter in some datastructure where we can search by the value of the sum and also get prefix that the sum belongs to (see below for implementation of this) If the sum of the prefix up to ...


1

I think I came up with a solution. Suppose the following numbers, and you want to find the first subarray to sum to 4: 2 -3 7 1 5 -1 First to get rid of negative numbers, I suggest find the smallest number (-3) and add its absolute value to all the numbers, that takes O(n), we have: 5 0 10 4 8 2 Then for any sub-array with size n, the sum should be ...


0

As with most programming problems, it depends, in my opinion. This issue is so intrinsic to creative work, that you should not forget that failures are going to happen, and that's O.K.. Programming is a wicked problem, and you usually don't know the right solution to the problem until you've already solved it. However, there's a host of local, specific ...



Top 50 recent answers are included