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
min = min(1, x, min*x, max*x, best*x)
max = max(1, x, max*x, max*x, best*x)
best = ...
// TODOSeq.splitMid
: track minPref
, minSuff
, maxPref
, maxSuff
, total
total
to properly construct prefix, suffix that accross middleMaximum 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