I need to find elements of a vector that are less than one of more elements that come after it. It\'s easy to do in a loop:
x = some_vector_values;
for m = 1
This should be an algorithm that takes O(n) time and O(n) memory: Label the last element in your array the maximum element. Iterate backwards over the array. Whenever you have an element smaller than your maximum, save it. Otherwise, it becomes your new maximum. This should get you all of the elements you need with a single pass.