Slot – 3
Question 1:
Lata is an English Teacher in a school and she asks student to find out the number of words and characters in a given sentence.
We have to write a program doing count of words and characters in the given sentence.
Example 1:
Lata is an english teacher
Output:
5
26
Example 2:
Welcome to Gate Knowledge
Output:
4
25
Solution
Language – Python
n = int(input())
for item in range(0,n):
str = input()
words = str.split(” “)
print(len(words))
print(len(str))
Question 2:
Given 2 strings str1 and str2. The task is to find the length of str1 after removing all the occurrence of str2 from it.
Example 1:
Str1: xxyzyzyv
Str2: xyz
Output:
2
Example 2:
Str1: abcabc
Str2: xyz
Output:
6
Solution
Language – Python
n = int(input())
for item in range(0,n):
str1 = input()
str2 = input()
while (True):
p = str1.find(str2)
if (p == -1):
break;
else:
str1 = str1.replace(str2,””);
print(len(str1))
Slot – 1
Question 1: (Number on Subset Problem)
Given an array of integers with size ‘num’ and another number ‘num2’. Also given a size ‘S’ (integer value) of the subset. The task is to find if the number num2 is present in every non-overlapping subset of size S in the given array. If its present in every subset print 1 otherwise print 0.
Example 1:
12
20 1 6 8 13 20 1 7 20 13 16 20
20
3
Output:
1
Example 2:
10
8 5 3 6 9 2 3 6 9 8
5
3
Output:
0
Solution
Language – Python
n = int(input())
l = list(map(int,input().split()))
search = int(input())
steps = int(input())
found = False
for i in range(0,n,steps):
found = False
for j in range(i,i+steps):
if j<n:
if(l[j]==search):
found = True;
if found:
continue
else:
print(0)
break;
if found:
print(1)
Related Links
- TCS NQT Coding Questions (21st Feb 2021) – Click Here