Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
We can actually have a subarray that maximizes the sum and contains a negative element in it. For example : [3,-1,5] ( The whole array maximizes the sum and has a -1 in it )
[-1,3,-1,5,1] ( [3,-1,5,1] maximizes the sum and has a -1 in it )
Wow, nice one.
How and why does this work?
I was focused on the 'contiguous' sub-array sum and kept trying to go for that with my first solution, but ended up giving up after failing to optimize my code. And I'm honestly disappointed in myself and dumbstruck at how simple this solution is, that I had to try it for myself.
Very nice solution!
I gotta remember to use sets more.
Nice.
I knew it worked out to be that simple, but I wanted to create the triangle as shown and really challenge myself to figure out the pattern and how to recreate it in code. My solution is not as succinct as yours, but I'm still happy with it.
Great job!
Nice one!