Skip to main content
replaced http://codereview.stackexchange.com/ with https://codereview.stackexchange.com/
Source Link

This is the code I ended up with that implements the approach I described in a recent answer to another question about the same problemrecent answer to another question about the same problem

This is the code I ended up with that implements the approach I described in a recent answer to another question about the same problem

This is the code I ended up with that implements the approach I described in a recent answer to another question about the same problem

Rollback to Revision 2
Source Link
Simon Forsberg
  • 59.8k
  • 9
  • 160
  • 312

Finding the sub-array with the maximum sum - my approach

This is the code I ended up with that implements the approach I described in a recent answer to another question about the same problem.

I have also added a parameterized JUnitJUnit test.

  • Any comments welcome.
  • Are there any edge-cases I'm missing? (I believe I've covered it all, many thanks to the folks in the 2nd Monitor for the discussion about the previous question).
  • I'm quite sure that it is possible to change the code to get rid of the inner for-loop entirely so that there will only be one for-loop. I have not completely investigated this though, but this code is still a massive improvement compared to the first version of my approach
  • How efficient is this code? Is it doing too much?
  • Expected complexity \$O(n)\$ (some indexes are currently iterated twice, but mostly it's just once)

##My approach

Finding the sub-array with the maximum sum

This is the code I ended up with that implements the approach I described in a recent answer to another question about the same problem.

I have also added a parameterized JUnit test.

  • Are there any edge-cases I'm missing? (I believe I've covered it all, many thanks to the folks in the 2nd Monitor for the discussion about the previous question).
  • I'm quite sure that it is possible to change the code to get rid of the inner for-loop entirely so that there will only be one for-loop. I have not completely investigated this though, but this code is still a massive improvement compared to the first version of my approach
  • How efficient is this code? Is it doing too much?
  • Expected complexity \$O(n)\$ (some indexes are currently iterated twice, but mostly it's just once)

Finding the sub-array with the maximum sum - my approach

This is the code I ended up with that implements the approach I described in a recent answer to another question about the same problem

I have also added a parameterized JUnit test.

  • Any comments welcome.
  • Are there any edge-cases I'm missing? (I believe I've covered it all, many thanks to the folks in the 2nd Monitor for the discussion about the previous question).
  • I'm quite sure that it is possible to change the code to get rid of the inner for-loop entirely so that there will only be one for-loop. I have not completely investigated this though, but this code is still a massive improvement compared to the first version of my approach
  • How efficient is this code? Is it doing too much?
  • Expected complexity \$O(n)\$ (some indexes are currently iterated twice, but mostly it's just once)

##My approach

deleted 25 characters in body; edited title
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

Finding the sub-array with the maximum sum - my approach

This is the code I ended up with that implements the approach I described in a recent answer to another question about the same problem.

I have also added a parameterized JUnitJUnit test.

  • Any comments welcome.
  • Are there any edge-cases I'm missing? (I believe I've covered it all, many thanks to the folks in the 2nd Monitor for the discussion about the previous question).
  • I'm quite sure that it is possible to change the code to get rid of the inner for-loop entirely so that there will only be one for-loop. I have not completely investigated this though, but this code is still a massive improvement compared to the first version of my approach
  • How efficient is this code? Is it doing too much?
  • Expected complexity \$O(n)\$ (some indexes are currently iterated twice, but mostly it's just once)

##My approach

Finding the sub-array with the maximum sum - my approach

This is the code I ended up with that implements the approach I described in a recent answer to another question about the same problem

I have also added a parameterized JUnit test.

  • Any comments welcome.
  • Are there any edge-cases I'm missing? (I believe I've covered it all, many thanks to the folks in the 2nd Monitor for the discussion about the previous question).
  • I'm quite sure that it is possible to change the code to get rid of the inner for-loop entirely so that there will only be one for-loop. I have not completely investigated this though, but this code is still a massive improvement compared to the first version of my approach
  • How efficient is this code? Is it doing too much?
  • Expected complexity \$O(n)\$ (some indexes are currently iterated twice, but mostly it's just once)

##My approach

Finding the sub-array with the maximum sum

This is the code I ended up with that implements the approach I described in a recent answer to another question about the same problem.

I have also added a parameterized JUnit test.

  • Are there any edge-cases I'm missing? (I believe I've covered it all, many thanks to the folks in the 2nd Monitor for the discussion about the previous question).
  • I'm quite sure that it is possible to change the code to get rid of the inner for-loop entirely so that there will only be one for-loop. I have not completely investigated this though, but this code is still a massive improvement compared to the first version of my approach
  • How efficient is this code? Is it doing too much?
  • Expected complexity \$O(n)\$ (some indexes are currently iterated twice, but mostly it's just once)
edited tags
Link
rolfl
  • 98.2k
  • 17
  • 220
  • 419
Loading
Tweeted twitter.com/#!/StackCodeReview/status/473625873636007936
Source Link
Simon Forsberg
  • 59.8k
  • 9
  • 160
  • 312
Loading