Jun-20-2020, 06:53 PM
Hi All,
Please could someone help with the error I am getting with my code
Description
Find the intersection of two sorted lists
Please could someone help with the error I am getting with my code
Description
Find the intersection of two sorted lists
Output:Input
[[1, 2, 3, 5, 9], [3, 6, 9, 12]]
Solution output
3
9
Expected output
[3, 9]
Testcase failed! The solution's output doesn't match the expected output.
Input
[[1, 1, 2, 4, 8, 8, 8, 9], [1, 2, 6, 7, 8, 8, 8]]
Solution output
1
2
8
8
8
Expected output
[1, 2, 8, 8, 8]
Testcase failed! The solution's output doesn't match the expected output.
Sorry posted wrong code and error!!!!also just to let me know what changes to be done in the linked code to get the desired output.# Reading the input import ast input_lists = ast.literal_eval(input()) # Write your code here # Python program to find intersection of # two sorted arrays # Function prints Intersection of arr1[] and arr2[] # m is the number of elements in arr1[] # n is the number of elements in arr2[] def printIntersection(arr1, arr2, m, n): i,j = 0,0 while i < m and j < n: if arr1[i] < arr2[j]: i += 1 elif arr2[j] < arr1[i]: j+= 1 else: print(arr2[j]) j += 1 i += 1 #def printArray(arr2): # j=0 # print(arr2[j]) # Driver program to test above function arr1 = input_lists[0] arr2 = input_lists[1] m = len(arr1) n = len(arr2) printIntersection(arr1, arr2, m, n) #printArray(arr2)I'm really new to python can anyone help me to correct the code