0% found this document useful (0 votes)
81 views

Tcs NQT Coding Questions

Uploaded by

crazyfact1320
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
81 views

Tcs NQT Coding Questions

Uploaded by

crazyfact1320
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

PROGRAMMING__LIFE_

TCS NQT CODING QUESTIONS

Shift:(3rd October 2024 FN):


1)You have recorded the duration of exercise (in minutes) you did each day for a week. The
durations are as follows:
Day 1: 25 minutes
Day 2: 26 minutes
Day 3: 23 minutes
Day 4: 15 minutes
Day 5: 14 minutes
Day 6: 38 minutes
Day 7: 44 minutes
Calculate the following:
The total minutes of exercise done in the week.
The average duration of exercise per day.
Expected Output:
Total exercise duration: 185 minutes
Average exercise duration per day: 26.4 minutes

2) Given a range [m,n] where 0≤m,n≤1000 ,find and print the total number of palindrome
numbers within that range (inclusive).
A palindrome number is a number that reads the same backward as forward. For example,
121 is a palindrome, while 123 is not.
Example Input 1:
Lowest range (m): 0
Highest range (n): 20
Example Output 1:
Total number of palindromes: 11
Explanation:
The palindrome numbers between 0 and 20 are: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11
Example Input 2:
Lowest range (m): 100
Highest range (n): 150
Example Output 2:
Total number of palindromes: 2
Explanation:
The palindrome numbers between 100 and 150 are: 101, 111

Shift:(3rd October 2024 AN):


3) Calculate the time taken by a train to cross a bridge when the speed of the train is given
by the user as input. The length of the train is 400 meters and the length of the bridge is 400
meters.
Details:
 The total distance (TD) the train needs to cover to completely cross the bridge is the
sum of the length of the train and the length of the bridge.
 Use the formula for time: Time=(800/SOT)×(18/5)
 Speed of train (SOT) is provided by the user and must satisfy the constraint:
1≤SOT≤200
Formula for calculating time: Time=(800/SOT)×(18/5)
Sample Input:
Speed of train = 72 Kmph
Explanation:
1. Calculate the total distance:
Total Distance=400 meters (length of train)+400 meters (length of bridge)=800 meter
s
2. Using the given speed of the train in the formula: Time=(800/72)*(18/5)
3. Calculate the result: Time=(800/72)*3.6=11.11*3.6=40 seconds
Output:
40 seconds
4) Given an array of even elements, divide it into two subarrays A and B such that the
average of both subarrays is the same. If it is possible, print "True". If not, print "False".
Example:
Input: {2, 2, 6, 4, 6}
Output: True
Explanation: The array can be divided into subarrays 2,6 and 2,4,6, both having the same
average:
o Average of subarray 2,6 = (2+6)/2=4
o Average of subarray 2,4,6 = (2+4+6)/3=54
Input: {2, 4, 6, 8}
Output: False
Explanation: There is no way to divide the array into two subarrays such that both have the
same average.

Shift:(4th October 2024 FN):


5) A perfect number is a positive integer that is equal to the sum of its proper divisors,
excluding itself. Write a function to check if a given number is a perfect number.
Input: 28
Output: True
Explanation: The proper divisors of 28 are 1, 2, 4, 7, and 14. The sum of these divisors is:
1+2+4+7+14=28.Since 28 is equal to the sum of its proper divisors, it is a perfect number.
Input: 12
Output: False
Explanation: The proper divisors of 12 are 1, 2, 3, 4, and 6. The sum of these divisors is:
1+2+3+4+6=16. Since 12 is not equal to the sum of its proper divisors, it is not a perfect
number.

6) Given a space-separated string of words, write a function to count the frequency of each
word in the string. The output should display each unique word followed by its frequency,
with the words in the order of their first appearance. The output should capitalize the first
letter of each word.
Example:
Input: apple banana apple banana apple orange banana
Output: Apple 3 Banana 2 Orange 1

Shift:(4th October 2024 AN):


7)You are given the time in seconds that an object took to cover 1000 meters. Write a
function to calculate the speed of the object in kilometers per hour (km/h).
Formula:
Speed (km/h)=(1000 meters/Time(Seconds))*3.6
Example:
1.Input:100
Output: 36 km/h
Explanation: The object took 100 seconds to cover 1000 meters. Using the formula:
Speed=(1000/100)×3.6=10×3.6=36 km/h
2.Input:200
Output: 18 km/h
Explanation: The object took 200 seconds to cover 1000 meters. Using the formula:
Speed=(1000/200)×3.6=5×3.6=18 km/h

8) You are given an integer array nums. You are initially positioned at the array's first
index, and each element in the array represents your maximum jump length at that
position. Write a function to determine if you can reach the last index of the array.
Return True if you can reach the last index, or False otherwise.
Examples:
1.Input: nums = [2, 3, 1, 1, 4]
Output: True
Explanation: Starting at index 0, you can jump to index 1 (jump length 2) and then
jump 3 steps to reach the last index.
2.Input:
nums = [3, 2, 1, 0, 4]
Output: False
Explanation: Starting at index 0, you can jump to index 1 (jump length 3) or index 2,
but you will be stuck at index 3 since its jump length is 0 and cannot reach the last
index.
Shift:(5th October 2024 FN):
9) Write a function that checks whether the sum of the digits of a given integer is
divisible by 3.
Input: A single integer n (0 ≤ 𝑛 ≤ 10^9)
Output: Print "Yes" if the sum of the digits of n is divisible by 3, otherwise print "No".
Example:
Input: 123
Output: Yes Explanation: The sum of the digits is 1+2+3=6, which is divisible by 3.
Input: 456
Output: No
Explanation: The sum of the digits is 4+5+6=15, which is divisible by 3. Input: 29
Output: Guess and comment it

10) Given an integer array and an integer k, write a function to return the count of all
unique pairs in the array whose difference is equal to k. A pair (a,b) is considered
unique if a≠b
Examples:
1.Input: nums = [1, 5, 3, 4, 2]
k=2
Output:3
Explanation: The unique pairs that have a difference of 2 are:
o (1, 3)
o (3, 5)
o (2, 4) Thus, the count is 3.
2.nums = [1, 1, 1, 1]
k=0
Output: 1
Explanation: There is only one unique pair (1, 1) that has a difference of 0

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy