TCS NQT - Coding Ability

Test Number 1


1 .A washing machine works on the principle of Fuzzy System, the weight of clothes put inside it for washing is uncertain But based on weight measured by sensors, it decides time and water level which can be changed by menus given on the machine control area.

For low level water, the time estimate is 25 minutes, where approximately weight is between 2000 grams or any nonzero positive number below that.

For medium level water, the time estimate is 35 minutes, where approximately weight is between 2001 grams and 4000 grams.

For high level water, the time estimate is 45 minutes, where approximately weight is above 4000 grams.

Assume the capacity of machine is maximum 7000 grams

Where approximately weight is zero, time estimate is 0 minutes.

Write a function which takes a numeric weight in the range [0,7000] as input and produces estimated time as output is: “OVERLOADED”, and for all other inputs, the output statement is

“INVALID INPUT”.

Input should be in the form of integer value –

Output must have the following format –

Time Estimated: Minutes

Example:

Input value
2000

Output value
Time Estimated: 25 minutes

      

#include< stdio.h >
void calculateTime(int n)
{
if(n==0)
printf("Time Estimated : 0 Minutes");
else if(n>0 && n<=2000)
printf("Time Estimated : 25 Minutes");
else if(n>2000 && n<=4000)
printf("Time Estimated : 35 Minutes");
else if(n>4000 && n<=7000)
printf("Time Estimated : 45 Minutes");
else
printf("INVALID INPUT");
}
int main()
{
int machineWeight;
scanf("%d",&machineWeight);
calculateTime(machineWeight);
return 0;
}


      

n = int(input())
if n==0:
print("Time Estimated : 0 Minutes")
elif n in range(1,2001):
print("Time Estimated : 25 Minutes")
elif n in range(2001,4001):
print("Time Estimated : 35 Minutes")
elif n in range(4001,7001):
print("Time Estimated : 45 Minutes")
else:
print("INVALID INPUT")





";

2.There is a JAR full of candies for sale at a mall counter. JAR has the capacity N, that is JAR can contain maximum N candies when JAR is full. At any point of time. JAR can have M number of Candies where M<=N. Candies are served to the customers. JAR is never remain empty as when last k candies are left. JAR if refilled with new candies in such a way that JAR get full.
Write a code to implement above scenario. Display JAR at counter with available number of candies. Input should be the number of candies one customer can order at point of time. Update the JAR after each purchase and display JAR at Counter.

Output should give number of Candies sold and updated number of Candies in JAR.

If Input is more than candies in JAR, return: “INVALID INPUT”

Given,

N=10, where N is NUMBER OF CANDIES AVAILABLE

K =< 5, where k is number of minimum candies that must be inside JAR ever.

Example 1:(N = 10, k =< 5)

Input Value
3
Output Value
NUMBER OF CANDIES SOLD : 3
NUMBER OF CANDIES AVAILABLE : 7
Example : (N=10, k<=5)

Input Value
0
Output Value
INVALID INPUT
NUMBER OF CANDIES LEFT : 10

#include< stdio.h >
int main()
{
int n=10, k=5;
int num;
scanf("%d",&num);
if(num>=1 && num<=5)
{
printf("NUMBER OF CANDIES SOLD : %d\n",num);
printf("NUMBER OF CANDIES LEFT : %d",n-num);
}
else
{
printf("INVALID INPUT\n");
printf("NUMBER OF CANDIES LEFT : %d",n);
}
return 0;
}

#include <iostream.h>
using namespace std;
int main()
{
int n=10, k=5;
int num;
cin>>num;
if(num>=1 && num<=5)
{
cout<< "NUMBER OF CANDIES SOLD : "<<num<<"\n";
cout<<"NUMBER OF CANDIES LEFT : "<<n-num;
}
else
{
cout<<"INVALID INPUT\n";
cout<<"NUMBER OF CANDIES LEFT : "<<n;
}
return 0;
}

import java.util.Scanner;
class Main{
public static void main(String[] args) {
int n = 10, k = 5;
int num;
Scanner sc = new Scanner(System.in);
num = sc.nextInt();
if(num >= 1 && num <= 5) {
System.out.println("NUMBER OF CANDIES SOLD : " + num);
System.out.print("NUMBER OF CANDIES LEFT : " + (n - num));
} else {
System.out.println("INVALID INPUT");
System.out.print("NUMBER OF CANDIES LEFT : " + n);
}
}
}

total_candies = 10
no_of_candies = int(input())
if no_of_candies in range(1, 6):
print('No. of Candies Sold:',no_of_candies)
print('No. of Candies Left:',total_candies-no_of_candies)
else:
print("Invalid Input")
print('No. of Candies Left:',total_candies)





";