Check out this important interview question asked in JPMorgan Data Engineer interviews.
Blog
Two strings are said to be complete if, upon concatenation, they contain all 26 English alphabets. For example, "abcdefghi" and "jklmnopqrstuvwxyz" are complete as they together have all characters from 'a' to 'z'.
You are given two sets of strings of sizes n and m respectively, and you need to find the number of pairs of strings, where one string is from the first set and the other is from the second set, such that the concatenation of the two strings is a complete string containing all 26 alphabets.
To solve this problem, we can follow these steps:
Here's the Python code to implement this solution:
def is_complete(s1, s2):
# Function to check if the concatenation of two strings contains all English alphabets
return set(s1 + s2) == set("abcdefghijklmnopqrstuvwxyz")
def count_complete_pairs(set1, set2):
# Function to count the number of complete pairs
count = 0
for s1 in set1:
for s2 in set2:
if is_complete(s1, s2):
count += 1
return count
# Example usage:
set1 = ["abcdefghi", "hello", "world", "python"]
set2 = ["jklmnopqrstuvwxyz", "example", "qwerty", "asdfg"]
count = count_complete_pairs(set1, set2)
print(count) # Output will depend on the input sets
This code will output the number of pairs from set1 and set2 that form a complete string.
Hope this helps you in your preparation.
Got questions?
Schedule a trial call with me; let's discuss. :)
Copyright ยฉ2024 Preplaced.in
Preplaced Education Private Limited
Ibblur Village, Bangalore - 560103
GSTIN- 29AAKCP9555E1ZV