c++ 0(n) solution
```\nint n=nums.size();\n        vectorvt1(n);\n        vectorvt2(n);\n        \n        vt1[0]=nums[0];\n        vt2[n-1]=nums[n-1];\n        for(int i=1;i=0;i
```\nint n=nums.size();\n        vector<int>vt1(n);\n        vector<int>vt2(n);\n        \n        vt1[0]=nums[0];\n        vt2[n-1]=nums[n-1];\n        for(int i=1;i<n;i++){\n            vt1[i]=max(vt1[i-1],nums[i]);\n           // vt2[i]=min(vt2[i-1],nums[i]);\n        }\n        for(int i=n-2;i>=0;i--){\n            vt2[i]=min(vt2[i+1],nums[i]);\n        }\n        \n       int ans=0;\n        for(int i=1;i<n-1;i++){\n            if(vt1[i-1]<nums[i] && vt2[i+1]>nums[i]){\n                ans+=2;\n            }\n            else if(nums[i-1]<nums[i]&&nums[i]<nums[i+1]){\n                ans++;\n            }\n            \n        }\n       \n        return ans;
[]