Created
June 29, 2020 01:04
-
-
Save megpay/69c8f8eea1baa7920135c1943e3fd723 to your computer and use it in GitHub Desktop.
Returning the mean of a list of salaries without the max or min salaries.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# From this problem on leetcode. | |
# https://leetcode.com/problems/average-salary-excluding-the-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: | |
# Input: salary = [4000,3000,1000,2000] | |
# Output: 2500.00000 | |
class Solution(object): | |
def average(self, salary): | |
""" | |
:type salary: List[int] | |
:rtype: float | |
""" | |
salary = sorted(salary) | |
numerator = float(sum(salary[1:len(salary)-1])) | |
denom = len(salary)-2 | |
return(numerator/denom) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment