Interview Query

Recency Weighted Salaries

Start Timer

0:00:00

Upvote
1
Downvote
Save question
Mark as completed
View comments (6)
Next question

Let’s say that you are working on analyzing salary data. You are tasked by your manager with computing the average salary of a data scientist using a recency weighted average, and you are provided data from the past ‘n’ years.

The recency weighting should ensure that the salaries from more recent years are weighted more heavily than the less relevant salaries of years that are farther in the past.

Write the function to compute the average data scientist salary given a mapped linear recency weighting on the data. In this case the input previous_salaries is a list of the salaries of the last n years and the list is ordered chronologically, with the most recent year coming last.

Round the result to two-digit numbers.

Example:

#input
previous_salaries = [64000,66000,75000,88000,90000]

#output
recency_weighted_salaries(previous_salaries) -> 81533.33

Explanation: We have the 5 salaries from the 5 years. We should give weight 1 to the first-year salary, 2 to the second one and so on till we reach the end and give weight 5 to the most recent year salary at the end.

result=640001+660002+750003+880004+9000051+2+3+4+5=81533.33result = \frac{64000 * 1 + 66000 * 2 + 75000 *3 + 88000 *4 +90000 *5} {1+2+3+4+5} = 81533.33

.
.
.
.
.


Comments

Loading comments