Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

3 sequential numbers

Name: eye 2012-04-04 16:06

Alright geniuses, if you think your programming ability is up to par, lets see you solve this:

Write an algorithm which in O(n) time finds 3 indices i, j, and k such that i < j < k and array[i] < array[j] < array[k].

Name: Anonymous 2012-04-06 18:02

Construct a B-tree out of the array that follows the following three rules:
1) Leaves added to the left of the parent denote "less than the value of the parent;" leaves to the right of the parent denote "greater than the value of the parent."
2) Duplicate values, when they are encountered, are ignored and are not added.
3) Maintain relative depth under the condition that whenever a leaf is added to the left, its relative depth is (re)set to 1 and whenever it is added to the right of the parent it is set to the parent's depth plus one.

This final rule allows that once you have sorted a node that will have depth 3, you have found a numeric organization (parent->right child->right child) of the array's elements that are in ascending positive value and have indicies of ascending value.  Maintain each parent's index on their node.  If you never sort to a depth of 3, the array has no such organization of elements that would satisfy the conditions.

In O(n) time.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List