Mean of Array After Removing Some Elements

As a Systems Engineer at Tata Consultancy Services, I deliver exceptional software products for mobile and web platforms, using agile methodologies and robust quality maintenance. I am experienced in performance testing, automation testing, API testing, and manual testing, with various tools and technologies such as Jmeter, Azure LoadTest, Selenium, Java, OOPS, Maven, TestNG, and Postman.
I have successfully developed and executed detailed test plans, test cases, and scripts for Android and web applications, ensuring high-quality standards and user satisfaction. I have also demonstrated my proficiency in manual REST API testing with Postman, as well as in end-to-end performance and automation testing using Jmeter and selenium with Java, TestNG and Maven. Additionally, I have utilized Azure DevOps for bug tracking and issue management.
Given an integer array arr, return the mean of the remaining integers after removing the smallest 5% and the largest 5% of the elements.
Answers within 10<sup>-5</sup> of the actual answer will be considered accepted.
LeetCode Problem - 1619
class Solution {
public double trimMean(int[] arr) {
Arrays.sort(arr); // Sort the array to easily trim the smallest and largest elements
double size = arr.length; // Get the total number of elements in the array
double five5Cent = size * (0.05); // Calculate 5% of the total size to determine how many elements to trim
double sum = 0; // Initialize a variable to hold the sum of the remaining elements
// Loop through the array from the 5% index to the end minus 5%
for(int i = (int)five5Cent; i < size - (int)five5Cent; i++){
sum += arr[i]; // Accumulate the sum of the remaining elements
}
// Return the mean of the remaining elements
return (sum / (size - five5Cent * 2)); // Calculate mean by dividing sum by the count of remaining elements
}
}




