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
7d

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
Stay ahead in your career. Get AmbitionBox app
qr-code
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

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter