I was going through a problem on CodeChef (https://www.codechef.com/problems/SUBINC) on counting subarrays which are strictly non-decreasing. Despite reading through the description several times, I was unable to decipher what I was expected to do.
I was mainly having a problem with two statements:
1)*"All valid subarrays are A[1, 1], A[1, 2], A[2, 2], A[3, 3], A[3, 4], A[4, 4]."*
If the subarray was 1 4 2 3, then how are A[2,2];A[3,3];A[3,4];and A[4,4] valid?(Given that it is non-decreasing only if forward elements are in decreasing order)Also why is A[1,1] valid?
2)"Only single subarray A[1, 1] is non-decreasing."
Similar problem here. If the array itself is only 1 then how can you count A[1,1] is a sub-array?
Perhaps I have completely failed to perceive what is to be done as this problem has been solved by many, but a bit of help would really be appreciated.
P.S I code in Java and am not so comfortable in C so that is why I could not understand most of the submissions.