Given 2 Arrays arr1[] & arr2[], for each element in arr10] find the same element in arr20] and print the index value, if not found print "NA". Assume arr1[] & arr2[] doesn't have duplicate values. o Input: ▪ Arr1 = ['A', 'B', 'C', 'D'] ▪ Arr2 = ['P', 'Q', 'A', 'D'] o Output: ▪ A-2 ▪ B - NA ▪ C - NA ▪ D-3 o Example
o Difficulty level - Easy
Ideal time required - 5 to 10 min
Attachments:
Answers
Answered by
25
Answer:
There are two sorted arrays. First one is of size m+n containing only m elements. Another one is of size n and contains n elements. Merge these two arrays into the first array of size m+n such that the output is sorted.
Input: array with m+n elements (mPlusN[]).
Answered by
1
Answer:
Explanation: # Python3 program for the above approach
# Function to find the longest
# subarray with the same element
def longest_subarray(arr, d):
(i, j, e) = (0, 1, 0)
for i in range(d - 1):
if arr[i] == arr[i + 1]:
j += 1
else:
j = 1
if e < j:
e = j
return e
arr = [ 1, 2, 3, 4, 5, 5, 5, 5, 5, 2, 2, 1, 1 ]
N = len(arr)
print(longest_subarray(arr, N))
Similar questions