[Javascript] Easy Solution | Prefix | Postfix
\n/**\n * @param {number[]} nums\n * @return {number}\n */\nvar sumOfBeauties = function(nums) {\n    \n    let preMin = [];\n    let postMax = [];\n    \n    p
```\n/**\n * @param {number[]} nums\n * @return {number}\n */\nvar sumOfBeauties = function(nums) {\n    \n    let preMin = [];\n    let postMax = [];\n    \n    preMin[0] = nums[0];\n    for (let i = 1; i < nums.length; i++) {\n        preMin[i] = Math.max(nums[i], preMin[i-1]); \n    }\n    \n    postMax[nums.length-1] = nums[nums.length-1];\n    for (let i = nums.length-2; i >= 0; i--) {\n        postMax[i] = Math.min(nums[i], postMax[i+1]);\n    }\n    \n    let ans = 0;\n    for (let i = 1; i < nums.length-1; i++) {\n        if (preMin[i-1] < nums[i] && nums[i] < postMax[i+1]) {\n            ans += 2;\n        }\n        else if (nums[i-1] < nums[i] && nums[i] < nums[i+1]) {\n            ans += 1;\n        }\n    }\n    \n    return ans;\n};\n```
['Dynamic Programming', 'JavaScript']