Skip to main content

Command Palette

Search for a command to run...

Average Salary Excluding the Minimum and Maximum Salary.

Published
2 min read
Average Salary Excluding the Minimum and Maximum Salary.
G

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.

You are given an array of unique integers salary where salary[i] is the salary of the i<sup>th</sup> employee.

Return the average salary of employees excluding the minimum and maximum salary. Answers within 10<sup>-5</sup> of the actual answer will be accepted.

LeetCode Problem: Link | Click Here

class Solution {
    public double average(int[] salary) {
        // Initialize variables to track minimum, maximum, sum, and length of the salary array
        int minSalary = Integer.MAX_VALUE; // Set initial minimum salary to the maximum possible integer value
        int maxSalary = Integer.MIN_VALUE; // Set initial maximum salary to the minimum possible integer value
        int sumAllSalary = 0; // Initialize the sum of all salaries
        int salaryLength = salary.length; // Get the length of the salary array

        // Iterate through the salary array to calculate sum, minimum, and maximum salaries
        for(int i=0; i<salaryLength; i++){
            sumAllSalary += salary[i]; // Add each salary to the total sum
            minSalary = Math.min(minSalary, salary[i]); // Update minimum salary if a smaller value is found
            maxSalary = Math.max(maxSalary, salary[i]); // Update maximum salary if a larger value is found
        }

        // Calculate the sum of salaries excluding the minimum and maximum values
        int excludeMinMaxSalary = sumAllSalary - (minSalary + maxSalary);
        // Calculate the average of salaries excluding the minimum and maximum values
        double averageSalaryExcludingMinMax = (double) excludeMinMaxSalary / (salaryLength - 2);
        return averageSalaryExcludingMinMax; // Return the calculated average salary excluding min and max
    }
}

More from this blog

S

Software and Performance Testing Insights

462 posts

Results-Driven Agile QA Specialist | Expert in Mobile & Web Testing | Proficient in Test Planning, Execution, and Root Cause Analysis.