TCS NQT PY & IMP Ques
TCS NQT PY & IMP Ques
1. Question:
Given workout data for 7 consecutive days in the following format:
1. Calculate the sum of the total workout time for the week.
2. Compute the average workout time per day, rounded to two decimal places.
Testcase:
Input:
Day 1 Monday:25
Day 2 Monday:26
Day 3 Monday:23
Day 4 Monday:15
Day 5 Monday:14
Day 6 Monday:38
Day 7 Monday:44
Output:
Sum of workout time: 185 minutes
Average workout time: 26.43 minutes
2. Question:
Given an array of even numbers, check whether it is possible to divide the array into subarrays
such that the sum of each subarray equals the average sum of elements of the entire array.
If such a division exists, return true; otherwise, return false.
Testcase:
Input:
2, 4, 6, 8
Output:
true
Explanation:
The average sum of elements is 20, and we can form two subarrays [8, 2] and [6, 4], both of
which sum to 10.
3. Question:
In a magical kingdom, the wizard Arithmo needs your help to find "Perfect Numbers." A perfect
number is defined as a number that is equal to the sum of its proper divisors (excluding itself).
Testcase:
Input:
6
Output:
6 is a perfect number.
Explanation:
The divisors of 6 are 1, 2, and 3. The sum of these divisors is 1+2+3=61 + 2 + 3 = 6. Hence, 6
is a perfect number.
4. Question:
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.
Testcase:
Input:
apple banana apple orange banana apple
Output:
apple 3 banana 2 orange 1
Explanation:
The word "apple" appears 3 times, "banana" appears 2 times, and "orange" appears 1 time in
the string. The order of appearance is maintained.
5. Question:
Given an integer, return true/True if the sum of its digits is even; otherwise, return
false/False.
Testcase:
Input:
123
Output:
true/True
Explanation:
The sum of the digits 1+2+3=61 + 2 + 3 = 6 is an even number, so the output is true/True.
6. Question:
Given an integer array nums, find the count of pairs (i, j) where i < j and nums[i] -
nums[j] = k.
Testcase:
Input:
Output:
Explanation:
The valid pairs are:
● (2, 1), (2, 1), (2, 1), and (2, 1) where the difference between the elements
equals k = 1.
7. Question:
Given an integer array and a target value, find all pairs of elements where the difference
between the elements is equal to the target. Return the list of such pairs.
Testcase:
Input:
nums = [4, 8, 6, 2], target = 4
Output:
[(8, 4), (6, 2)]
Explanation:
The differences between elements 8 and 4, as well as 6 and 2, equal the target value 4.
8. Question:
Given speed and time as inputs, calculate and print the distance.
Testcase:
Input:
Speed: 60 km/h
Time: 3 hours
Output:
180 km
Explanation:
Distance is calculated using the formula Distance=Speed×Time
9. Question:
Write a program to find and print all strong numbers from a given integer array. A strong
number is defined as a number equal to the sum of the factorial of its digits.
Testcase:
Input:
[1, 2, 145, 10]
Output:
[1, 145]
Explanation:
145 is a strong number because 1!+4!+5!=145; 1! + 4! + 5! = 145
10. Question: Given an array of integer values, find all empty packets (represented by 0 ) and
push them to the end of the array.
Test Case:
Explanation: The empty packets represented by 0 are moved to the end while maintaining the
order of the other elements.
11. Question: Find two numbers in an array that add up to a specific target.
Test Case:
12. Question: Rotate an array to the right K times and print the result.
Test Case:
Explanation: After rotating the array 2 times to the right, the result is [4, 5, 1, 2, 3].
13. Question: Find the element that appears only once in an array where every other element
appears twice.
Test Case:
Explanation: The number 1 appears only once, while all other numbers appear twice.
14. Question: Given an array of integers and an integer sum, return the total number of
subarrays whose sum equals the given value.
Test Case:
Explanation: The subarrays [1, 2], [3], [1, 1, 1], and [2,all1]
have a sum equal to
3.
15. Question: Given an integer array nums, find the subarray with the largest sum and return its
sum.
Test Case:
16. Question: Given an array of strings, remove all duplicate strings and return the updated
array.
Test Case:
17. Question: Given an integer array arr, find the count of elements whose value is greater
than all of its prior elements.
Test Case:
18. Question: Given an array of risk levels (integers ranging from 0 to 2 ), sort the array based
on these risk levels.
Test Case:
Test Case:
Test Case:
Test Case:
Test Case:
23. Question: Find duplicates in an array in linear time and constant space.
Test Case:
Test Case:
Explanation: The mean is the sum of elements divided by the count (16/5 = 3.2), and the
median is 3 .
25. Question: Find the smallest and second smallest elements in an array.
Test Case:
Test Case:
Test Case:
Explanation: Elements are sorted in decreasing order of frequency, with ties broken by original
appearance.
www.primecoding.in
WWW.PRIMECODING.IN