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.
Be the first one to answer
Add answer anonymously...
Top Cuemath Software Developer interview questions & answers
Popular interview questions of Software Developer
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app