Oxygen Level

TCS Coding Question 2

Selection of MPCS exams include a fitness test which is conducted on ground. There will be a batch of 3 trainees, appearing for running test in track for 3 rounds. You need to record their oxygen level after every round. After trainee are finished with all rounds, calculate for each trainee his average oxygen level over the 3 rounds and select one with highest oxygen level as the most fit trainee. If more than one trainee attains the same highest average level, they all need to be selected.

TCS Coding Question 2 Slot 1

Display the most fit trainee (or trainees) and the highest average oxygen level.

Note:

  • The oxygen value entered should not be accepted if it is not in the range between 1 and 100.
  • If the calculated maximum average oxygen value of trainees is below 70 then declare the trainees as unfit with meaningful message as “All trainees are unfit.
  • Average Oxygen Values should be rounded.

Example 1:

  • INPUT VALUES

            95

            92

            95

            92

            90

            92

            90

            92

            90

  • OUTPUT VALUES
    • Trainee Number : 1
    • Trainee Number : 3

 

Note:

Input should be 9 integer values representing oxygen levels entered in order as

 

Round 1

  • Oxygen value of trainee 1
  • Oxygen value of trainee 2
  • Oxygen value of trainee 3

 

Round 2

  • Oxygen value of trainee 1
  • Oxygen value of trainee 2
  • Oxygen value of trainee 3

 

Round 3

  • Oxygen value of trainee 1
  • Oxygen value of trainee 2
  • Oxygen value of trainee 3

 

Output must be in given format as in above example. For any wrong input final output should display “INVALID INPUT”

18 comments on “Oxygen Level”


  • Dpa

    t=[0,0,0]
    res=[]
    v,j,k,nc=0,0,0,0
    while(k<=8):
    olevel=int(input())
    if(1<olevel<=100):
    t[v]=t[v]+olevel
    j+=1
    if(j==3):
    t[v]=t[v]//3
    v+=1
    j=0
    else:
    print("Enter valid input")
    olevel=int(input())
    if(100<olevel or olevel<1):
    nc+=1
    if(nc==1):
    k-=1
    nc=0
    k+=1

    r=t
    m=max(t)

    for i in r:
    if(i==m):
    ind=r.index(i)
    res.append(ind+1)
    r[ind]=0

    m=max(r)
    ind=r.index(i)
    res.append(ind+1)

    for i in res:
    print("Trainee Number: ",i,end="\n")


  • Vineela

    // simple code in java
    Scanner sc=new Scanner(System.in);
    int t1=0,t2=0,t3=0,n=1;
    while(n=1)&&(k<=100))
    {
    if(n%3==1) {
    t1+=k;
    n++;
    }
    else if(n%3==2)
    {
    t2+=k;
    n++;
    }
    else
    {
    t3+=k;
    n++;
    }
    }
    else n++;
    }
    t1=t1/3;
    t2=t2/3;
    t3=t3/3;
    if(t1<70 && t2<70 && t3<70) System.out.println("all trainees are unfit");
    else
    {
    int ans=Math.max(Math.max(t1, t2),t3);
    if(ans==t1) System.out.println("t1 is fit");
    if (ans==t2) System.out.println("t2 is fit");
    if(ans==t3) System.out.println("t3 is fit");
    }


  • Anil

    matrix=[]
    for i in range(3):
    a=[]
    for j in range(3):
    a.append(int(input()))
    matrix.append(a)
    sum1,sum2,sum3=0,0,0
    for i in range(3):
    for j in range(3):
    if j==0:
    sum1=sum1+matrix[i][j]

    if j==1:
    sum2=sum2+matrix[i][j]
    if j==2:
    sum3=sum3+matrix[i][j]
    x=[]
    x.append(sum1//3)
    x.append(sum2//3)
    x.append(sum3//3)
    if x[0]<70 or x[1]<70 or x[2]=x[1] and x[0]>=x[2]:
    print(“trainee 1”)
    if x[1]>=x[2] and x[1]>=x[0]:
    print(“trainee 2”)
    if x[2]>=x[0] and x[2]>=x[1]:
    print(“trainee 3”)


  • Ajay

    #simplified code in python
    trainees = 3
    track_round = 3
    t = []
    for x in range(1,4):
    for y in range(1,4):
    oxy_level = int(input(“enter oxygen level “))
    t.append(oxy_level)
    if(oxy_level in range(0,100)):
    print(“oxy_level after round “,x,”of trainee”,y)
    else:
    print(“invalid input”)
    t1 = []
    t2 = []
    t3 = []
    t1.append(t[0])
    t1.append(t[3])
    t1.append(t[6])
    t2.append(t[1])
    t2.append(t[4])
    t2.append(t[7])
    t3.append(t[2])
    t3.append(t[5])
    t3.append(t[8])
    sum1 = 0
    sum2 =0
    sum3 =0
    for x in range(0,len(t1)):
    sum1 = sum1 + t1[x]
    for x in range(0,len(t2)):
    sum2 = sum2 + t2[x]
    for x in range(0,len(t3)):
    sum3 = sum3 + t3[x]

    l = [sum1,sum2,sum3]
    if(sum1>=sum2 and sum1>70 and sum1>=sum3):
    print(“Traninee Number : 1”)
    if(sum2>=sum1 and sum2>=sum3 and sum2>70):
    print(“Trainee Number : 2”)
    if(sum3>=sum1 and sum3>=sum2 and sum3>70):
    print(“Trainee Number : 3”)
    else:
    print(“All trainees are unfit”)


  • Vaibhav

    import java.util.*;
    public class Tcs {

    public static void main(String []args){

    Scanner sc=new Scanner(System.in);
    int a[]=new int[9];
    int b[]=new int[3];
    int n;
    System.out.println(“enter oxygen level of 3 players of 3 rounds”);

    for(int i=0;i=1&&n<=100)
    a[i]=n;
    else
    {
    System.out.println("invalid input");
    return;
    }
    }

    b[0]=(a[0]+a[3]+a[6])/3;
    b[1]=(a[1]+a[4]+a[7])/3;
    b[2]=(a[2]+a[5]+a[8])/3;
    int max =Arrays.stream(b).max().getAsInt();
    if(max<70)
    System.out.println("All trainees are unfit");

    else
    {

    for(int i=0;i<3;i++)
    {
    if(b[i]==max)
    {

    System.out.println("Trainee Number :"+(i+1)+" with oxygen level "+max);

    }
    }
    }

    }

    }