132 Pattern


There is an O(n) time, O(1) space solution, which I have posted:
https://discuss.leetcode.com/topic/111297/onsolutionsinglepasso1memorynostacknomalloc
It is a little bit longer than others but not more complex

There's also a solution using TreeMap to scan array one time to find the largest rightside element that is smaller than the step value and keep record the smallest leftside element that is smaller than the step value. The running time of this algorithm is O(nlgn) and space cost is O(n)