Find the maximum sum of lengths of non-overlapping subarrays (contiguous elements) with `k`

as the maximum element of each subarray.

`arr = [2, 1, 4, 9, 2, 3, 8, 3, 4]`

and `k = 4`

should return `5`

since `[2, 1, 4]`

has a length of `3`

and `[3, 4]`

has a length of `2`

, total `5`

.

`arr = [1, 2, 3, 2, 3, 4, 1]`

and `k = 4`

should return `7`

since `[1, 2, 3, 2, 3, 4, 1]`

has a length of `7`

.

You are not signed in. You can only run/submit code after signing in. Create your free Codela account now!