Last Updated: 17 Mar, 2021

Fitness Test In Indian Navy

Easy
Asked in company
HSBC

Problem statement

Selection in the Indian Navy includes a fitness test which is conducted in the seawater. In this test, there will be a group of 3 trainees appearing for the swimming test in the sea for three rounds. The oxygen level remaining of each trainee will be recorded after each round in 2D matrix/list ‘OXYGEN’ of size 3 x 3.

After the trainee is finished with all rounds, an Officer from the Indian Navy calculates each trainee's remaining oxygen level over the three rounds and selects one with the highest average oxygen level as the fittest trainee. If more than one trainee attains the same highest average level, they all need to be chosen.

The final result of the test will depend upon the following factors :

1. The remaining oxygen level should only be  accepted if it is in the range between [1, 100] both inclusive else the oxygen level will be marked as 0.
2. If the calculated maximum average oxygen remaining value of trainees is below 70, then declare the trainees as unfit with the meaningful message as “Unfit.”
3. The average remaining Oxygen level should be rounded.

For Example :

img

Output for the above case will be
Trainee1
Unfit
Trainee3

Because the maximum average is 70 which is in the range and Trainee 1 and 3 both have the same value.
Trainee 2 is unfit because the average is below 70. 
Input Format :
The first line of input contains an integer 'T' which denotes the number of test cases to be run. Then the test cases follow.

The next 3 lines of each test case contain 3 space-separated integers denoting the oxygen level of each trainee after each round.
Output Format :
For each test case, print the fittest trainee. If more than one trainee has the same highest average oxygen level then print all of them in increasing order.

Print “Unfit” if the average oxygen level is less than 70.

Print the output of each test case in a separate line.

Note :

You do not need to print anything; it has already been taken care of. Just implement the given function.
Constraints :
1 <= ‘T’ <= 100
1 <= ‘OXYGEN[i][j]’ <= 100 

Where ‘OXYGEN[i][j]’ denotes the oxygen level of 'ith' candidate after 'jth' round.

Time Limit: 1 sec

Approaches

01 Approach

The idea behind this approach is to calculate the average of all the rounds and store them in an array/list and then calculate the maximum of all the average remaining oxygen levels. If more than one have the same value then print the trainee number and if average is less than 70 then simply print “Unfit”.

 

Here is the complete algorithm:

  • Make an array/list ‘answer’ of type string to store the final answer.
  • Iterate the ‘OXYGEN’ of all the trainee’s and do the following:
    • If the value is less than 1 or greater than 100 update it to 0.
  • Make an array/list ‘average’ of size 3 to store the average of all the remaining oxygen levels of 3 trainees.
  • Find the maximum value in the ‘average’ and store it in the ‘max_average’ variable.
  • Iterate the ‘average’ and for each index do the following:
    • If ‘average[i]’ = ‘max_average’ then insert string “Trainee” + (‘i’+1) in the ‘answer’.
    • If the ‘average[i]’ is less than 70 then insert “Unfit” in the ‘answer’.
  • Finally, return ‘answer’.