The Mountain Subsequence — Solution & Editorial
Compute the longest increasing subsequence ending at each i and the longest decreasing subsequence starting at each i; the peak is inc[i] + dec[i] − 1. (Each side is O(N log N) with patience sorting.)
Complexity: O(N2) here