First argument is an integer array A of size N.
Second argument is an integer array B of size M.
Return an integer array denoting the common elements.
Input > A = [1, 2, 2, 1], B = [2, 3, 1, 2], out > [1, 2, 2]
Input > A = [2, 1, 4, 10], B = [3, 6, 2, 10, 10], out > [2, 10]
Code is below I got the proper out, but for higher number of elements i m getting errror
def solve(A, B):
result = []
for element in A:
if element in B:
result.append(element)
B.remove(element)
return result
DO i need to do generator yield functionality for this