For each index i , we will find out the closest index j to the left , such that the number in the index is greater than it , and see if there exists an index k for which the number at index k is less that the number at index i,

we maintain an array dp , that stores the closes index to the left such that it is greater that the number at any index , building this dp array is O(n).

```
class Solution {
public:
bool find132pattern(vector<int>& nums) {
int i,j,k,n;
n = nums.size();
if(n<3)
return false;
vector<int> mn(nums.begin(),nums.end());
for(i=1;i<n;i++)
mn[i] = min(mn[i],mn[i-1]);
int dp[n]{-1};
for(i=0;i<n;i++)
{
j = i-1;
while(j!= -1 && nums[j]<=nums[i])
j = dp[j];
dp[i] = j;
}
for(i=2;i<n;i++)
{
j = dp[i];
if(j>0 && mn[j-1]<nums[i])
return true;
}
return false;
}
};
```