Common Elements Problem Statement
Identify and output the common strings present in both given arrays of lowercase alphabets for each test case.
Input:
The first line contains an integer 'T' representing the number of test cases.
For each test case:
First line: Two integers 'N' and 'M' denoting the sizes of the two arrays.
Second line: 'N' space-separated strings representing elements of the first array.
Third line: 'M' space-separated strings representing elements of the second array.
Output:
For each test case, output the common strings in a single line, separated by spaces,
following the order they appear in the second array. Print each line separately for each test case.
Example:
Input:
T = 1
N = 4, M = 3
Array 1 = ["ab", "dc", "ab", "ab"]
Array 2 = ["dc", "ab", "ab"]
Output:
"dc ab ab"
Constraints:
- 1 <= T <= 10
- 1 <= N, M <= 10000
- 1 <= S ≤ 10 (where 'S' is the length of the strings)
- Strings contain only lowercase alphabets
- Time limit: 1 second
Note:
No need to explicitly print the output, just return the result as specified.

AnswerBot
4mo
The task is to find common strings in two arrays of lowercase alphabets for each test case.
Iterate through the elements of the second array and check if they are present in the first array.
Use a hash ...read more
Help your peers!
Add answer anonymously...
Cuemath Software Developer interview questions & answers
A Software Developer was asked Q. Remove the Kth Node from the End of a Linked List You are given a singly Linked ...read more
A Software Developer was asked Q. Common Elements Problem Statement Identify and output the common strings present...read more
A Software Developer was asked Q. Distinct Subsequences Problem Statement You are given a string 'S' of length 'N'...read more
Popular interview questions of Software Developer
A Software Developer was asked Q1. Remove the Kth Node from the End of a Linked List You are given a singly Linked ...read more
A Software Developer was asked Q2. Common Elements Problem Statement Identify and output the common strings present...read more
A Software Developer was asked Q3. Distinct Subsequences Problem Statement You are given a string 'S' of length 'N'...read more
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

