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

 
Constraints:

3 <= salary.length <= 100
10^3 <= salary[i] <= 10^6
salary[i] is unique.
Answers within 10^-5 of the actual value will be accepted as correct.

Source: leetcode | Difficulty: EASY
Tags: Sorting

Data structures

Starter code: class Solution:
    def average(self, salary: List[int]) -> float:
        

Solutions:
class Solution:

	def average(self, salary: List[int]) -> float:
		salary.sort()
		del salary[0]
		del salary[-1]
		return sum(salary) / len(salary)


class Solution:

	def average(self, salary: List[int]) -> float:
		mx = 0
		mn = 100005
		sm = 0
		n = len(salary) - 2
		for i in salary:
			if i > mx:
				mx = i
			if i < mn:
				mn = i
		print((mn, mx))
		return (sum(salary) - (mn + mx)) / n


class Solution:

	def average(self, salary: List[int]) -> float:
		minSalary = min(salary)
		maxSalary = max(salary)
		total = sum(salary)
		return (total - minSalary - maxSalary) / (len(salary) - 2)


class Solution:

	def average(self, salary: List[int]) -> float:
		salary.sort()
		salary.pop()
		salary.pop(0)
		return sum(salary) / len(salary)


class Solution:

	def average(self, salary: List[int]) -> float:
		minSalary = None
		maxSalary = None
		s = 0
		for n in salary:
			s = s + n
			if minSalary is None or n < minSalary:
				minSalary = n
			if maxSalary is None or n > maxSalary:
				maxSalary = n
		return (s - minSalary - maxSalary) * 1.0 / (len(salary) - 2)


class Solution:

	def average(self, salary: List[int]) -> float:
		return (sum(salary) - min(salary) - max(salary)) / (len(salary) - 2)


class Solution:

	def average(self, salary: List[int]) -> float:
		s = salary[:]
		max_ind = 0
		min_ind = 0
		for i in range(1, len(s)):
			if s[max_ind] < s[i]:
				max_ind = i
			elif s[min_ind] > s[i]:
				min_ind = i
		print((max_ind, min_ind))
		if max_ind < min_ind:
			del s[max_ind]
			del s[min_ind - 1]
		else:
			del s[min_ind]
			del s[max_ind - 1]
		return sum(s) / len(s)


class Solution:

	def average(self, salary: List[int]) -> float:
		salary.sort()
		newSalaryList = salary[1:-1]
		numSalaries = len(newSalaryList)
		return sum(newSalaryList) / numSalaries