Simple easy to understand Java solution using PriorityQueue | Java
\tclass Solution {\n\t\tpublic int sumOfBeauties(int[] nums) {\n\n\t\t\tint n = nums.length;                             //length of nums array\n\n\t\t\tPriorit
\tclass Solution {\n\t\tpublic int sumOfBeauties(int[] nums) {\n\n\t\t\tint n = nums.length;                             //length of nums array\n\n\t\t\tPriorityQueue<Integer> left = new PriorityQueue<>(Comparator.reverseOrder());  //max heap\n\t\t\tPriorityQueue<Integer> right = new PriorityQueue<>();                          //min heap\n\n\t\t\tleft.offer(nums[0]);\n\t\t\tfor(int i = 1; i < n; ++i) {\n\t\t\t\tright.offer(nums[i]);\n\t\t\t}\n\n\t\t\tHashSet<Integer> indices = new HashSet<>();\n\t\t\tint count = 0;\n\t\t\tfor(int i = 1; i < n - 1; ++i) {\n\t\t\t\tint leftTop = left.peek();\n\t\t\t\tleft.offer(nums[i]);\n\t\t\t\tright.poll();\n\n\t\t\t\tif(nums[i] > leftTop && nums[i] < right.peek()) {\n\t\t\t\t\tcount++;\n\t\t\t\t\tindices.add(i);\n\t\t\t\t}\n\t\t\t}\n\t\t\tint beauty = 2 * count;              //beauty for each index that satifies the first conditon is 2\n\t\t\tfor(int i = 1; i < n - 1; ++i) {\n\t\t\t\tif(nums[i] > nums[i - 1] && nums[i] < nums[i + 1] && !indices.contains(i)) {\n\t\t\t\t\tbeauty++;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn beauty;\n\t\t}\n\t}
[]