Java easy solution using Stack.
Simplest and basic approach of Nearest greater to the left and nearest smaller to right and get this done. \n\n\n# Code\n\nclass Solution {\n    ArrayList<Integ
Simplest and basic approach of Nearest greater to the left and nearest smaller to right and get this done. \n\n\n# Code\n```\nclass Solution {\n    ArrayList<Integer>vec1=new ArrayList<>();\n    ArrayList<Integer>vec2=new ArrayList<>();\n    \n    public void lg(int [] nums){\n        Stack<Integer>st=new Stack<>();\n        int i=0;\n        while(i<nums.length){\n            \n            if(st.size()==0)vec1.add(-1);\n            else if(st.peek()>=nums[i]){\n                vec1.add(st.peek());\n            }else{\n                while(!st.empty() && st.peek()<nums[i]){\n                    st.pop();\n                }   \n                \n                if(st.empty())vec1.add(-1);\n                else vec1.add(st.peek());\n            }\n            \n            st.push(nums[i]);\n            i++;\n        }\n    }\n    \n    public void rs(int nums[]){\n        \n        Stack<Integer>st=new Stack<Integer>();\n        \n        int i=nums.length-1;\n        \n        while(i>=0){\n            \n            if(st.empty())vec2.add(-1);\n            else if(st.peek()<=nums[i]){\n                vec2.add(st.peek());\n            }else{\n                while(!st.empty() && st.peek()>nums[i]){\n                    st.pop();\n                }   \n                if(st.empty())vec2.add(-1);\n                else vec2.add(st.peek());\n            }\n            \n            st.push(nums[i]);\n            i--;\n        }\n        Collections.reverse(vec2);\n       \n    }\n    \n    public int sumOfBeauties(int[] nums) {\n        lg(nums);\n        rs(nums);\n        int sum=0;\n        for(int i=1;i<nums.length-1;i++){\n            if(vec1.get(i)==-1 && vec2.get(i)==-1)sum+=2;\n            else if(nums[i]>nums[i-1] && nums[i]<nums[i+1])sum++;\n        }\n        return sum;\n    }\n}\n```
['Array', 'Stack', 'Java']