Join Regular Classroom : Visit ClassroomTech

CODE Gladiators by Cognizant Solutions | Question 1

Question 1: Virus Outbreak

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 the 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

Time Limit(X):
0.50 sec(s) for each input.
Memory Limit:
512 MB
Source Limit:
100 KB
Allowed Languages:
C, C++, C++11, C++14, C#, Java, Java 8, Kotlin, PHP, PHP 7, Python, Python 3, Perl, Ruby, Node Js, Scala, Clojure, Haskell, Lua, Erlang, Swift, VBnet, Js, Objc, Pascal, Go, F#, D, Groovy, Tcl, Ocaml, Smalltalk, Cobol, Racket, Bash, GNU Octave, Rust, Common LISP, R, Julia, Fortran, Ada, Prolog, Icon, Elixir, CoffeeScript, Brainfuck, Pypy, Lolcode, Nim, Picolisp, Pike, pypy3

Solution:

Python 3.8

''' 
Read input from STDIN. Print your output to STDOUT 
'''
    #Use input() to read input from STDIN and use print to write your output to STDOUT
def check(s1,s2):
    a=len(s1)
    b=len(s2)
    i=j=0
    while j<a and i<b:
        if s1[j] == s2[i]:
            j+=1
        i+=1
    return j==a


def main():
    v=input()
    n=int(input())
    x=[]
    for i in range(n):
        x.append(input())

    for i in x:
        print("POSITIVE" if check(i,v) else "NEGATIVE")  

main()

''' End '''

-Proof of Working-

proof

Follow us

Also Checkout