prefixMax with the same length as nums and set prefixMax[0] to nums[0].nums starting from index 1 to the end, updating prefixMax at each index with the maximum value between nums[i] and prefixMax[i-1].suffixMin with the same length as nums and set suffixMin[nums.length - 1] to nums[nums.length - 1].nums starting from the second to last index to the beginning, updating suffixMin at each index with the minimum value between nums[i] and suffixMin[i+1].totalBeauty to 0.nums from index 1 to nums.length - 2. For each index i, check:
nums[i] is greater than prefixMax[i-1] and less than suffixMin[i+1], add 2 to totalBeauty.nums[i] is greater than nums[i-1] and less than nums[i+1], add 1 to totalBeauty.totalBeauty.