Tcs NQT Coding Questions
Tcs NQT Coding Questions
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
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
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