TCS NQT Coding Solve| 1 pm

MCQ

1. 14
2. A
3. A[9]
4. Finalize
5. Static
6. Linked list, array
7. Agile
8. 25
9. 4 updated
10. 1

Question 1: Subset Problem

#Correct Solution in Python

n=int(input())
x=list(map(int,input().split(' ')))
N2=int(input())
S=input()

t=0
r=0
m=0
while t<len(x):
    z=x[t:t+3]
    #print(z)
    if z.count(N2)>=1:
        r+=1
    
    t=t+3
    m+=1
    
if m==r:
    print(1)
else:
    print(0)

Question 2: ATM Problem

#Correct Solution in Python

def count(S, m, n):
    table = [[0 for x in range(m)] for x in range(n+1)]
 

    for i in range(m):
        table[0][i] =1
    for i in range(1, n+1):
        for j in range(m):
 
            
            x = table[i - S[j]][j] if i-S[j] >= 0 else 0
 
        
            y = table[i][j-1] if j >= 1 else 0
 
        
            table[i][j] = x + y
 
    return table[n][m-1]

m = eval(input()) 
arr = input().split()
for i in range(len(arr)):
    arr[i]=int(arr[i])
    

n = eval(input())
print(count(arr, m, n))

Follow Us

You Missed

Also Checkout