@ncbaoyanan For a 123 sequence, scan from right to left, use two variables v3, v2 to keep track of the largest candidate for s3 and s2 found so far. For example, v3 get updated if the next number is larger than v3, v2 gets updated if you see a number that is larger than v2 but less than v3... Once you see a variable less than the candidate for s2, a sequence is found.

132 Pattern