LeetCode — Average Salary Excluding minimum and maximum salary

Given an array of unique integers salary where salary[i] is the salary of the employee i.

Return the average salary of employees excluding the minimum and maximum salary.

Example 1:

Input: salary = [4000,3000,1000,2000]
Output: 2500.00000
Explanation: Minimum salary and maximum salary are 1000 and 4000 respectively.
Average salary excluding minimum and maximum salary is (2000+3000)/2= 2500

Example 2:

Input: salary = [1000,2000,3000]
Output: 2000.00000
Explanation: Minimum salary and maximum salary are 1000 and 3000 respectively.
Average salary excluding minimum and maximum salary is (2000)/1= 2000

Example 3:

Input: salary = [6000,5000,4000,3000,2000,1000]
Output: 3500.00000

Example 4:

Input: salary = [8000,9000,2000,3000,6000,1000]
Output: 4750.00000

Solutions:

Time complexity: O(n), traveling salary array list once

Space complexity: O(1), storing result into avgSalary variable.

--

--

--

Dell Technologies — VxRail Software Engineer 👨‍💻

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Red Hat OpenShift

Why Windows with its 20H2 update is the best OS for FullStack Developer

{UPDATE} Карточная Игра Белка на айфон Hack Free Resources Generator

Middleware In .NET Core

String Interpolation in Scala

Knoldus-blog-footer-image

Mornings, Nights, and Weekends: How I Changed Careers and Became a Programmer

Creating a cooldown system in Unity.

Why product managers should mentor at hackathons?

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Steven Lu

Steven Lu

Dell Technologies — VxRail Software Engineer 👨‍💻

More from Medium

Search Insert Position (Solution For Leetcode Problem #35)

Frog Jump

Lowest Common Ancestor of a Binary Search Tree 🐳

[Leetcode] Backspace String Compare