cover me in ashes

mardi


Problem of the day

A sequence of integers is called a "minimum-centered" sequence if it is of odd length and the middle element is the smallest.

For example, 12 13 8 9 10 is a minimum-centered sequence, so is 9 7 3 1 8 6 10. However, 7 2 1 3 5 2 8 isn't.

Given an array of numbers, find the longest consecutive sequence of numbers in this array that is minimum-centered.

Alternate easier problem: Find if there exists a minimum-centered sequence of a given length in this array.

Complexity needed: O(n) [ linear ] for both problems. Of course, if you can come up with an O(n) solution for the second one, there is an easy O(n log n) solution for the first one based on binary search, but that's not we're looking for.

Credit to Daniel for informing me about this problem and its somewhat elegant solution.

posted by ncmhp @ 25.10.05

covermeinashes : a syndicated collective

covermeinashes is:
anodyne. wayward wordsmith latter day aesculapius.
ncmhp. ....
fcs
.
tormented lover poet bard.

diversions

contrails

Powered by Blogger