Help needed in MAXSEGM

I am getting WA for my solution
What’s wrong with my logic?. Please help.
Question link:

There are two mistakes in your solution.
First the way of initializing vis array! (Go ahead and print the array values after initializing :slight_smile: )
Second, in the if part you are doing s = w[i] which means that you are assigning to s the sum of all the values upto i, which is incorrect. It should store the sum between ptr1 and ptr2. You can fix it by doing something like s += w[i] - (i > 0? w[i-1] : 0).

Hope it helps :smile:

Edit: There is one more mistake. Try to figure that out yourself first. If fails then see the hint!


Try to find the answer for this
0 1 2 3 1 0 2 3
1 1 1 1 1 1 1 1

Yup!! Got it. Thanks::slightly_smiling_face: