125k views
1 vote
There are N boxers competing in the boxing championship. The championship is categorized into 5 classes of weights A, B, C, D and F, where class A is for the players with weight between 66 and 75 kg, class B for player with weight between 76 and 85 kg, and so on till class F for players with weight from 106 Kg or more. Each player defines the class of his competition based on his initial weight. However, some player can do some effort before the competition to change their weight by moving to one class ahead or backward. For example, player can move from class C to class D by gaining some weights or from class C to B by losing some weights. They can do so without any condition.

Given the initial weight of the players, write an algorithm that can predict the two classes with the maximum and minimum possible number of players as well as such expected numbers.
Design an algorithm with less complexity solving it
Example
Players [1,2,3,4,5,6,7,8,9,10]
Class of weight [A,C,B,C,D,D,A,B,B,D]
Output
Minimum number of players exists in Class C with 8 players
Maximum number of player may exist in Class F with 3 players

1 Answer

2 votes

To find the two classes with the minimum and maximum number of players, initialize counters for each class and iterate through the list of player weights, incrementing the counter of their corresponding class. Finally, find the class with the minimum and maximum counter values.

To find the two classes with the maximum and minimum possible number of players, we can use a counting algorithm to keep track of the number of players in each class. We initialize counters for each class and iterate through the list of player weights. For each player, we increment the counter of their corresponding class. At the end, we find the class with the minimum and maximum counter values to determine the two classes with the minimum and maximum number of players.

Initialize counters for each class: A = 0, B = 0, C = 0, D = 0, F = 0.

Iterate through the list of player weights.

For each player, increment the corresponding class counter.

Find the class with the minimum counter value to determine the class with the minimum number of players.

Find the class with the maximum counter value to determine the class with the maximum number of players.

Return the classes and their respective number of players.

User George Simms
by
7.5k points