Lecture 006

Strategies:

• Using Seq.iterate for slice with low, high indice

• Using Seq.splitMid for answer either lie in left, right, or middle

Maximum Contiguous Sequence Product: we need both min and max because input can be negative

• Seq.iterate: track min, max, best

• each step, update min = min(1, x, min*x, max*x, best*x)
• each step, update max = max(1, x, max*x, max*x, best*x)
• each step, update best = ...// TODO
• Seq.splitMid: track minPref, minSuff, maxPref, maxSuff, total

• each step, update them accordingly
• answer is either in left, right, or some suffix + prefix
• we need total to properly construct prefix, suffix that accross middle

Maximum Contiguous Sequence Product Wrap Around: we can wrap around in circle

• reduce it to Maximum Contiguous Sequence Product

• Minimum Contiguous Sequence Product within Maximum Contiguous Sequence Product

• Negate sign of input to get Minimum Contiguous Sequence Product

• Do normal Maximum Contiguous Sequence Product

• Combine them

Skyline Density Bruteforce

• for every skyline position: $O(n^2)$

• we find minimum height between pair with scan $O(n)$ work, $O(\log n)$ span

• calculate density $O(1)$

Skyline Density

Table of Content