Problem statementMahi is working on a program to find the intersection of two sorted arrays.Help Mahi by writing a function that takes two sorted arrays and their sizes as input and prints the common elements (intersection) of the two sorted arrays.Function Specificationsvoid findIntersection(int arr1[], int size1, int arr2[], int size2)Input format :The first line of input contains an integer value 'N1', representing the number of elements in the first array.The second line of input consists of N1 space-separated integers arr1[i], representing the elements of the first sorted array.The third line of input contains an integer value 'N2', representing the number of elements in the second array.The fourth line of input consists of N2 space-separated integers arr2[i], representing the elements of the second sorted array.Output format :The output displays display the intersection of the two arrays, with elements separated by spaces.Refer to the sample output for the formatting specifications.Code constraints :In this scenario, the test cases fall under the following constraints:1 ≤ N1, N2 ≤ 101 ≤ arr1[i], arr2[i] ≤ 100Sample test cases :Input 1 :41 2 3 432 4 6Output 1 :2 4 Input 2 :71 2 3 4 5 6 754 5 6 7 8Output 2 :4 5 6 7 Input 3 :101 2 3 4 5 6 7 8 9 101010 20 30 40 50 60 70 77 100 78Output 3 :10
Question
Problem statementMahi is working on a program to find the intersection of two sorted arrays.Help Mahi by writing a function that takes two sorted arrays and their sizes as input and prints the common elements (intersection) of the two sorted arrays.Function Specificationsvoid findIntersection(int arr1[], int size1, int arr2[], int size2)Input format :The first line of input contains an integer value 'N1', representing the number of elements in the first array.The second line of input consists of N1 space-separated integers arr1[i], representing the elements of the first sorted array.The third line of input contains an integer value 'N2', representing the number of elements in the second array.The fourth line of input consists of N2 space-separated integers arr2[i], representing the elements of the second sorted array.Output format :The output displays display the intersection of the two arrays, with elements separated by spaces.Refer to the sample output for the formatting specifications.Code constraints :In this scenario, the test cases fall under the following constraints:1 ≤ N1, N2 ≤ 101 ≤ arr1[i], arr2[i] ≤ 100Sample test cases :Input 1 :41 2 3 432 4 6Output 1 :2 4 Input 2 :71 2 3 4 5 6 754 5 6 7 8Output 2 :4 5 6 7 Input 3 :101 2 3 4 5 6 7 8 9 101010 20 30 40 50 60 70 77 100 78Output 3 :10
Solution
Here is a step-by-step solution in C++ for the problem:
#include<iostream>
using namespace std;
void findIntersection(int arr1[], int size1, int arr2[], int size2)
Similar Questions
Find the Intersection of Two ArraysA scientist is analyzing data from two different experiments. Each experiment produces a list of unique results. The scientist needs to find the common results (intersection) from both experiments to identify consistent findings.Write a function that finds the intersection of two arrays of integers.Constraints:NAExample:Input:51 2 3 4 554 5 6 7 8Output:4 5Explanation:Input:5 ---->Size of first array1 2 3 4 5 --->Elements of first array5 ---->Size of second array4 5 6 7 8 --->Elements of second arrayOutput:4 5 ---->Common elements from first and second array
Write a function, which prints all numbers in common between two given arrays, with each number printed only once. The function returns number of common elements.Assume that both arrays contain each number only once.int common(int *a, int lena, int *b, int lenb);Note: the function does printing.Note: in the output shown, the last number printed is the return value of the function common.
Rohit is tasked with writing a program to check if two integer arrays are equal. The program should take two arrays as input and determine whether they are equal, i.e., they have the same elements in the same order.Your task is to help Rohit to complete this task.Input format :The first line of input consists of an integer N, representing the size of the first array.The second line consists of N space-separated integers, representing the elements of the first array.The third line consists of an integer M, representing the size of the second array.The fourth line consists of M space-separated integers, representing the elements of the second array.Output format :If the two arrays are equal, the output prints "Equal". Else, print "Not Equal".Refer to the sample output for formatting specifications.Code constraints :1 ≤ N, M ≤ 101 ≤ array elements ≤ 1000Sample test cases :Input 1 :31 2 331 2 3Output 1 :EqualInput 2 :31 2 341 2 3 4Output 2 :Not EqualInput 3 :378 96 54378 54 96Output 3 :Not Equal
Write a program to eliminate the common elements in the given 2 arrays and print only the non-repeating elements and the total number of such non repeating elements.Input Format:The first line contains space separated values, denoting the size of the two arrays in integer format respectively.The next two lines contains the space-separated integer arrays to be compared.Sample Input:5 41 2 8 6 52 6 8 10Sample Output:1 5 103
Single File Programming QuestionProblem StatementGiven two arrays of size N, write a program to merge the arrays of integers into a single array by interleaving their elements. Input the size N and the elements of both arrays. Implement a solution that interleaves the elements alternately from both arrays and outputs the merged array.For Example, If the arrays are {12, 28, 54} and {48, 67, 35}, then the resultant array is {12, 48, 28, 67, 54, 35}.Note: This question helps in solving the technical coding tests in Infosys, Capgemini and TCS.Input format :The first line of input consists of an integer N, representing the size of the arrays.The second line consists of N space-separated elements of the first array.The third line consists of N space-separated elements of the second array.Output format :The output prints the resultant array.Code constraints :1 ≤ N ≤ 101 ≤ array elements ≤ 250Sample test cases :Input 1 :512 15 19 23 1834 31 78 59 65Output 1 :12 34 15 31 19 78 23 59 18 65 Input 2 :312 28 5448 67 35Output 2 :12 48 28 67 54 35
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.