Techgig Codegladiator contest Problem 1 and 2

Spread the love

techgig codegladiator organised by COGNIZANT here are two problems of the contest check out.

Cognizant is looking to hire the best developers in this year’s edition of TechGig Code Gladiators. Over 50K+ developers have already registered. Register now to win prizes worth up to INR 50 Lakhs.

here is the link: techgig codegladiator

1) Virus Outbreak (100 Marks)

In the Martian land faraway, a new virus has evolved and is attacking the individuals at a fast pace. The scientists have figured out the virus composition, V. The big task is to identify the people who are infected. The sample of N people is taken to check if they are POSITIVE or NEGATIVE. A report is generated which provides the current blood composition B of the person.

POSITIVE or NEGATIVE ?

If the blood composition of the person is a subsequence of the virus composition V, then the person is identified as POSITIVE otherwise NEGATIVE.

Example:

Virus Composition, V = coronavirus

Blood Composition of the person , B = ravus

The person in question is POSITIVE as B is the subsequence of the V.

The scientists are busy with their research for medicine and request you to build a program which can quickly figure out if the person is POSITIVE or NEGATIVE. They will provide you with the virus composition V and all the people’s current blood composition. Can you help them?

Note: The virus and blood compositions are lowercase alphabet strings.

Input Format:

The first line of the input consists of the virus composition, V

The second line of he input consists of the number of people, N

Next N lines each consist of the blood composition of the ith person, Bi

Constraints
1<= N <=10

1<= |B|<= |V|<= 10^5

Output Format:
For each person, print POSITIVE or NEGATIVE in a separate line

Sample TestCase 1
Input

coronavirus
3
abcde
crnas
onarous

Output

NEGATIVE
POSITIVE
NEGATIVE

 

def main():
testCase = int(input())
while testCase>0:
LR = list(map(int,input().strip().split()))
lst=[]
for i in range(LR[0],LR[1]+1):
isPrime = True
for num in range(2, int(i ** 0.5) + 1):
if i % num == 0:
isPrime = False
break
if isPrime:
lst.append(i)

n=len(lst)
if n>1:
print(max(lst)-min(lst))
elif n==1:
print(0)
else:
print(-1)

testCase -=1
main()

 

2) Prime Game (100 Marks)

Rax, a school student, was bored at home in the pandemic. He wanted to play but there was no one to play with. He was doing some mathematics questions including prime numbers and thought of creating a game using the same. After a few days of work, he was ready with his game. He wants to play the game with you.

GAME:

Rax will randomly provide you a range [ L , R ] (both inclusive) and you have to tell him the maximum difference between the prime numbers in the given range. There are three answers possible for the given range.

There are two distinct prime numbers in the given range so the maximum difference can be found.

There is only one distinct prime number in the given range. The maximum difference in this case would be 0.

There are no prime numbers in the given range. The output for this case would be -1.

To win the game, the participant should answer the prime difference correctly for the given range.

techgig codegladiator

Example:

Range: [ 1, 10 ]

The maximum difference between the prime numbers in the given range is 5.

Difference = 7 – 2 = 5

Range: [ 5, 5 ]

There is only one distinct prime number so the maximum difference would be 0.

Range: [ 8 , 10 ]

There is no prime number in the given range so the output for the given range would be -1.

Can you win the game?

techgig codegladiator organized by COGNIZANT.

Input Format
The first line of input consists of the number of test cases, T

Next T lines each consists of two space-separated integers, L and R

 

Constraints
1<= T <=10

2<= L<= R<=10^6

 

Output Format
For each test case, print the maximum difference in the given range in a separate line.

Sample TestCase 1
Input
5
5 5
2 7
8 10
10 20
4 5

Output
0
5
-1
8
0
Explanation

Test Case 1: [ 5 – 2 ] = 3

Test Case 2: [ 7 – 2 ] = 5

Test Case 3: No prime number in the given range. Output = -1

Test Case 4: [ 19 – 11 ] = 8

Test Case 5: The difference would be 0 since there is only one prime number in the given range.

 

n=input()
a=int(input())
for i in range (a):
p=”
k=input()
j=0
t=0
x=len(n)
y=len(k)
while(j<x and t<y):
if n[j]==k[t]:
p=p+n[j]
j=j+1
t=t+1
else:
j=j+1
if p==k:
print(“POSITIVE”)
else:
print(“NEGATIVE”)

check the tcs nqt coding contest 2021

174 thoughts on “Techgig Codegladiator contest Problem 1 and 2”

  1. I have been browsing online more than 4 hours today, yet
    I never found any interesting article like yours.

    It is pretty worth enough for me. Personally, if all website owners and bloggers made good
    content as you did, the internet will be much more useful than ever before.

    Reply

Leave a Comment