Fastest Solution (time = O(n)), completed in 84ms
This is the fastest solution, far ahead of the second.\n\n\n\n/**\n * @param {number[]} nums\n * @return {number}\n */\nvar sumOfBeauties = function(nums) {\n  
This is the fastest solution, far ahead of the second.\n![image](https://assets.leetcode.com/users/images/60e2af43-7f05-4ece-8e42-f24abf7d376f_1650304049.7672899.png)\n\n```\n/**\n * @param {number[]} nums\n * @return {number}\n */\nvar sumOfBeauties = function(nums) {\n    let min = nums[0], max = Infinity, maxArr = [], total = 0;\n    \n\t// Creating an array, which will keep the record of minimum values from last index\n    for(let i=nums.length-1; i>1; i--) {\n        if(nums[i] < max) max = nums[i];\n        maxArr.push(max);\n    }\n\n\t// iterating through array to check the given conditions\n    for(let i=1; i<nums.length-1; i++) {\n\t\n\t\t// Keeping a record of max value from all index < i\n        if(nums[i-1] > min) min = nums[i-1];\n\t\t\n\t\t// Checking conditions\n        if(nums[i] < maxArr.pop() && min < nums[i]) total += 2;\n        else if(nums[i-1] < nums[i] && nums[i] < nums[i+1]) total += 1;\n    }\n    \n    return total;\n};\n```\n\nIf you have any doubt, I will be very happy to clear it. **Please upvote if you like this.**
['JavaScript']