Given two strings str1 and str2, write code to find out if all non-unique elements in str2 are in str1?

Problem Given two strings str1 and str2, write code to find out if all non-unique elements in str2 are in str1? Solution Method 1 - Using hashset on str2 and boolean array or hashset on str2 Break down the problem into two tasks. i) Finding the non-unique i.e. repeating elements in str 1. Hashing can be used for this purpose. ii) Finding if all the characters hashed in the first string are available in the second string. [Read More]

Given two strings A and B, how would you find out if the characters in B were a subset of the characters in A?

Here is a code in c: #include <stdio .h> #include <conio .h> int isSubset(char \*a, char \*b); int main(){ char str1="defabc"; char str2="abcfed"; if(isSubset(str1, str2)==0) printf("\\nYes, characters in B=%s are a subset of characters in A=%s\\n",str2,str1); } else { printf("\\nNo, characters in B=%s are not a subset of characters in A=%s\\n",str2,str1); } getch(); return(0); } // Function to check if characters in "b" are a subset // of the characters in "a" int isSubset(char \*a, char \*b) { int letterPresent256256; int i; for(i=0; i<256; i++) letterPresentii=0; for(i=0; aii! [Read More]