So, I made a program that calculates the starting and the ending point of the longest subsequence of an array...

So, I made a program that calculates the starting and the ending point of the longest subsequence of an array, which has the following property: the sum of the elements is less than 2. The array only contains positive integers.
Here's the code snippet:
for (int i=0; iinb4 your code is ugly as hell
Just started programming in c++

probably wont work on some corner cases. have you tested it enough, you can automate the test to check if it gets correct on all kinds of pathological sequences

I tested it to some data that is on the uni's website, it gives correct answers. The weird thing is, if I change this line:
Sum+=Sum_Arr[j];

to this:
Sum+=Sum_Arr[i];

it gives 93/100 and I think this is absolutely bullshit.
My professor said that the tester isn't buggy, cause some other students got 100/100's. I don't know what's happening.

what is Max ? and what is it initialized as

Max is the length of the last longest subsequence and it is initialized as 0

well i guess the tester is bugged then lol. tell your professor and show him.

maybe the tester is just trying a couple of pre made sequences and it just happen to get correct with sum_arr[i] on those.

I already showed him and he told me that I shouldn't go from 0 to M with both of the cycles. But I think it's right that way.

also what about the sequence (1000, 1,1,1} it gets wrong on that one

ignore

i mean show him how the tester scores 93/100 on a wrong implementation

I told him and he only told me that the tester is not bugged, cause some other students got 100's on the same problem with the same tester, so something is wrong with my code.

Then you are not calculating Max correctly. If i == j, what's the length of the subsequence? It's 1, not 0, since it contains a single element. Similarly if i == 4 and j == 5, the length is 2 not 1. Max should be j - i + 1.

Well, does it matter if I only need the starting and the ending point? Also, I changed the code, and now it gives me 55/100, and 84/100 with the j/i swap.

try a new design where it only counts 0 and tops at first 1, which is what it kinda does anyways. i bet you can make it much simpler this way

With the 93/100 solution I tested it with this input: 0 0 1 5 1 0 0 0 and it gives 0 2, which is a wrong output. The 64/100 solution gives the correct 4 7 solution. Don't know what is this.

try to put max as int_min or something.

Same error. I think this is bullshit, why do I even try, if the wrong implementation give 93% and the good one only 64

It shouldn't stop at the first 1, only if the current subseqence contain a 1, so it's really the same that way.

no need, cant be negative length.

for optimization you should not do i++ , since if you find a sequence from say i= 0 to j= 4, then the next test is from i = 1, but of course that will be a shorter sequence. so next i should be from 4.

Not true, if the sequence is 1 0 0 1 0 0, then here first finds 1 0 0, then finds 0 0 1 0 0, and that's the longest subsequence

No, it shouldn't matter. I didn't pay attention though, your while loop will (almost) always break at j == (end) + 1, so Max = j - i is correct, you already have the 1 added.

It looks correct as far as I can tell. Possible reasons I can imagine it failing:
>you're somehow fucking up on data input/output
>some inputs will have multiple correct solutions, the tester program is bad and only considers one of them correct, while your program returns another subsequence which is of the same length but has different start and end indices
>check your output when the input has no solution (i.e. all numbers in the array are >= 2); too lazy to do it in my head, but what is the output supposed to be and what does your program output?

>you're somehow fucking up on data input/output
I read in the data correctly, and that still does not answer the thing that if I swap j with i, it gives 93.
>some inputs will have multiple correct solutions, the tester program is bad and only considers one of them correct, while your program returns another subsequence which is of the same length but has different start and end indices
The program should return the first longest subseq start and end points, and it does that
>check your output when the input has no solution (i.e. all numbers in the array are >= 2); too lazy to do it in my head, but what is the output supposed to be and what does your program output?
If no sequence was found, the program should return a 0, and it does that in my full code; if max is equal to 0 in the end, I return 0

So really, I have no idea what is this.

>if I swap j with i, it gives 93
Probably just random chance
Are you sure you're not missing something stupid, such as the requirement being "

yes, I do everything right. well, I guess I'll give up, will still get an A with this 93/100, cause my other problems were 100/100. I'm almost sure this is a bug with the tester