5 kyu
Socialist distribution (performance edition)
Description:
This kata is based on the Socialist distribution by GiacomoSorbi. It is advisable to complete it first to grasp the idea, and then move on to this one.
Task
You will be given a list of numbers representing the people's resources, and an integer - the minimum wealth each person must possess. You have to redistribute the resources among the people in such way that everybody would fulfil the minimum-wealth requirement.
The redistribution step consists of 2 operations:
- taking 1 unit of the resource from the first richest person in the list
- giving 1 unit of the resource to the first poorest person in the list
This process is repeated until everybody hits the minimum required wealth level.
Note: there's always enough resources for everybody.
Example (step by step)
distribution([4, 7, 2, 8, 8], 5) == [5, 6, 5, 6, 7]
0. [4, 7, 2, 8, 8]
+ -
1. [4, 7, 3, 7, 8]
+ -
2. [4, 7, 4, 7, 7]
+ -
3. [5, 6, 4, 7, 7]
+ -
4. [5, 6, 5, 6, 7]
Algorithms
Performance
Similar Kata:
Stats:
Created | Nov 16, 2019 |
Published | Nov 17, 2019 |
Warriors Trained | 372 |
Total Skips | 23 |
Total Code Submissions | 703 |
Total Times Completed | 44 |
Python Completions | 44 |
Total Stars | 8 |
% of votes with a positive feedback rating | 88% of 20 |
Total "Very Satisfied" Votes | 16 |
Total "Somewhat Satisfied" Votes | 3 |
Total "Not Satisfied" Votes | 1 |
Total Rank Assessments | 4 |
Average Assessed Rank | 5 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 6 kyu |