TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Algorithmic Puzzle: Continuous Increasing Subsequences

1 pointsby bor0about 4 years ago

1 comment

cousin_itabout 4 years ago
It&#x27;s much simpler, if there&#x27;s an increasing run of length k, it contains k(k+1)&#x2F;2 subruns. So you can just do one pass over the array, keeping track of the length of the current run.<p><pre><code> function f(arr) { var j=0, ret=0; for (var i=1; i&lt;=arr.length; i++) { if (i==arr.length || arr[i]&lt;=arr[i-1]) { ret += (i-j)*(i-j+1)&#x2F;2; j = i; } } return ret; }</code></pre>