Fitness Test In Indian Navy

Easy
0/40
Average time to solve is 15m
profile
Contributed by
2 upvotes
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. 
Detailed explanation ( Input/output format, Notes, Images )
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
Sample Input 1 :
2
10 50 30
30 80 90
60 90 80
90 90 90
70 70 70
0 101 98
Sample Output 1 :
Unfit
Unfit
Trainee3
Trainee1
Unfit

Explanation For Sample Output 1 :

For the first test case:
Following are the average of remaining oxygen levels of 3 trainees:
1. (10 + 50 + 30) / 3 = 30, which is less than 70 so the trainee is unfit.
2. (30 + 80 + 90) / 3 = 66.66, which becomes 66 on rounding up which is less than 70 so the trainee is unfit. 
3. (60 + 90 + 80) / 3 = 76.66, which becomes 76 on rounding up which is in the range and maximum among all.

For the second test case:
Following are the average of remaining oxygen level of 3 trainees:
1. (90 + 90 + 90) / 3 = 90, so the trainee’s average oxygen level is in the range.
2. (70 + 70 + 70) / 3 = 70, so the trainee’s average oxygen level is in the range.
3. (0 + 0 + 98) / 3 = 66.33. Here, we added 0 instead of 101 because as given in the problem the value out of the range [1, 100] is to be treated as 0. 66.33 on rounding up gives 66 which is less than 70 so the trainee is unfit.
Trainee1 is the fittest among all and trainee3 is unfit.
Sample Input 2 :
1
55 56 84
94 85 76
12 21 34
Sample Output 2 :
Unfit
Trainee2
Unfit

Explanation For Sample Output 2 :

For the first test case:
Following are the average of remaining oxygen level of 3 trainees:
1. (55 + 56 +84) / 3 = 65, which is less than 70 so the trainee is unfit.
2. (94 + 85 +76) / 3 = 85, which is in the range.
3. (12 + 21 + 34) / 3 = 22.33, which becomes 22 on rounding up. which is less than 70 so the trainee is unfit.
Trainee2 is fittest among all and trainee 1 and 3 are Unfit.
Hint

Try to use brute force approach in this problem by calculating the average of all the rounds. 

Approaches (1)
Brute Force

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’.
Time Complexity

O(1).

 

Because we are iterating 2D array/list ‘OXYGEN’ of size 3 X 3 so the overall iterations will be constant and hence the overall  time complexity will be O(1).

Space Complexity

O(1).

 

Because we are not using any extra space to calculate the final result.

Code Solution
(100% EXP penalty)
Fitness Test In Indian Navy
Full screen
Console