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 22:52

>>49
That's interesting, but it's O(n^2). Consider running it on:

[13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 0, 1, 2]

But that's still a good improvement over the O(n^3) solution. There might be some error in it though. Because of the insertion order and no balancing, the parent elements will always have an array index less than its children. But the array index relationship among siblings is lost. It could be that the solution consists of 3 cousins, rather than a node to right child to right grand child.

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