Skip to content

Instantly share code, notes, and snippets.

@semafor
Last active July 4, 2018 11:33
Show Gist options
  • Save semafor/7f503a628e79f13423736f0b8612f7c2 to your computer and use it in GitHub Desktop.
Save semafor/7f503a628e79f13423736f0b8612f7c2 to your computer and use it in GitHub Desktop.
// assumes intervals to be sorted on Start then End
highWaterMark := epoch
sum := 0
for interval := intervals
if interval.End.Before(highWaterMark) continue
sum += between(
max(highWaterMark, interval.Start),
max(highWaterMark, interval.End)
)
highWaterMark = interval.End
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment