Algorithmic Puzzle: Continuous Increasing Subsequences
bor0.wordpress.com
Algorithmic Puzzle: Continuous Increasing Subsequences
1–2 of 2 posts
Re: Algorithmic Puzzle: Continuous Increasing Subsequences
#2It's much simpler, if there's an increasing run of length k, it contains k(k+1)/2 subruns. So you can just do one pass over the array, keeping track of the length of the current run.
function f(arr) {
var j=0, ret=0;
for (var i=1; i