Message from C, C++ talks

June 2019

— Yep

— Exactly.
My idea is, you have one loop
Before it you remember the first value as previous and start the loop from the second item
Also have count and max_count values set to 0
In the loop
1) you check that the value is bigger than previous
1.1) if 1) is true, you increment count and remove the value
1.2) if not, you check that count bigger than max_count
1.2.1) if 1.2.1) true then max_count = count
1.2.2) set count to zero
1.2.3) set previous to current value

max_count (or -1) probably would be the answer

Message permanent page

— Numbering is broken by the way :)

— Hope you get the idea, but not sure if it works :)


After removing the larger values , I will be left with another small array of levels of pesticides and this again needs to be sorted out by removing the rightside value if it's bigger

— So doing it again will need an another loop

— My idea that in this loop you always keep the part on the left in the state when there are no ascending values. So after this loop you'll get the result as if you do all the loops.

The difference with the approach that is described in the task, that here you always look at the last valid value. Not on the value that was probably removed.

Message permanent page

— Ok wait, i got what you said

— I will implement it tommorow morning.

— Thanks btw, nice approach

— NP, I still not completely sure if it works :D

— I think it will work

— Yes

— Oh, and also, I think the removement of elements can be eliminated here somehow. It can be faster without removement, also in real world situation you may want to keep the data immutable.

Message permanent page

— Also if I remove elements then step 1.2.3 messes up