GeeksforGeeks » Interview Questions
Microsoft Interview Question for Software Engineer/Developer (Fresher) about Strings
(6 posts)-
Your are given two strings A and B. Output true if all the character in string A are present in String B. The solution should be optimal in time and space.
For egs..
A="ppppppppppaaaaaaaaaa"
B="pa"
Output = trueproblem is that u cant check each character of a with entire b tht is not optimal.
-
split string A, and put each char into a set to remove the duplicated chars, and then check whether the chars in B is contained in the set. By doing this, we can get the answer in O(m+n).
-
make a hash table or array of 256 element
a[256];
for(int i=0;*(s1+i);i++){
a[*(s1+i)]++;
}
for(j=0;*(s2+j);j++){
if(*(s2+j))
printf("no");
}
printf("yes");
} -
quicksort the string A and for each char in B do binary search
-
For the the question
our are given two strings A and B. Output true if all the character in string A are present in String B. The solution should be optimal in time and space.V can first remove all the duplicates from the string A and then check if those characters are present in B
-
Quick sort both the strings in O(nlogn). Remove the duplicate in O(n) in both the strings.
Then compare the element of both the strings(already sorted) like we do for merging.
Reply
You must log in to post.