All JobsHOMEInterview Experience

Infosys asked Coding Questions

Infosys asked Coding Questions 2024

Check Questions in PDF Below

 

 

def getCount(N, M, A, B):
MOD = 10**9 + 7

# Calculate 2^N % MOD and 2^M % MOD
totalSubsetsA = pow(2, N, MOD)
totalSubsetsB = pow(2, M, MOD)

# Total number of pairs of subsets (S1, S2)
totalPairs = (totalSubsetsA * totalSubsetsB) % MOD

return totalPairs

# Get input from user
N = int(input(“Enter the number of elements in set A (N): “))
M = int(input(“Enter the number of elements in set B (M): “))

A = list(map(int, input(f”Enter {N} elements of set A separated by space: “).split()))
B = list(map(int, input(f”Enter {M} elements of set B separated by space: “).split()))

# Ensure the input lists match the specified lengths
if len(A) != N or len(B) != M:
print(“The number of elements does not match the specified lengths.”)
else:
# Calculate and print the result
result = getCount(N, M, A, B)
print(“Total number of different pairs of subsets:”, result)

# Example usage:
# N = 3
# M = 3
# A = [1, 2, 3]
# B = [4, 5, 6]
# Output: 64

 

 

 

 

 

def longestLength(N, K, A):
max_length = 0
current_or = 0
start = 0

for end in range(N):
current_or |= A[end]

while current_or > K and start <= end:
current_or &= ~A[start]
start += 1

if current_or <= K:
max_length = max(max_length, end – start + 1)

return max_length

# Example usage
N = int(input(“Enter the number of elements in the array (N): “))
K = int(input(“Enter the value of K: “))
A = list(map(int, input(f”Enter {N} elements of the array separated by space: “).split()))

if len(A) != N:
print(“The number of elements does not match the specified length.”)
else:
result = longestLength(N, K, A)
print(“Maximum length of subarray whose bitwise OR is less than or equal to K:”, result)

 

 

Click Here to Download Questions

 

One thought on “Infosys asked Coding Questions

Leave a Reply

Your email address will not be published. Required fields are marked *