Given array *A* of *N* < = 500000 elements and each *A*[*i*] < = *N*. Find number of partitions of array into some number of subsegments such that every subsegment has length greater or equal to minimum value of subsegment and smaller or equal to maximum value of subsegment.

Example:*A* = {1, 6, 2, 3, 4, 3, 4}

Partitions are:

|1|6, 2, 3, 4, 3, 4|

|1, 6, 2|3, 4, 3, 4|

|1, 6, 2, 3|4, 3, 4|

|1|6, 2|3, 4, 3, 4|

|1|6, 2, 3|4, 3, 4|

|1, 6|2, 3|4, 3, 4|

How to solve this problem?

Problem link

But there is no editorial.

Isn't it a little strange that this is the only problem from Codechef August Long Challenge 2018 that one can't find a single word about in Codechef discussions?

Moreover, no one has ever even asked anything about it...

Anyone?

Here is the approach that was shared by tmwilliamlin168 6 months ago (in August 2018 that is).