1. IImplement the function below. Your function should search “inputString” for any possible anagram of “matchSet.” That is, any contiguous set of characters that contains every character in “matchSet” in any order, exactly once, and with no extra characters in the set. Return the index of the starting point of the first match, or -1 if no match is found. Return -1 if no match is found. Optimize for speed assuming that “matchSet” and “inputString” may both be very large.
For example:
findString("ba", "cccabcc"); //returns 3
findString("cat", "cacatcatc"); //returns 2
findString("ba", "ccccccc"); //returns -1
int findString(string matchSet, string inputString)
{
// your code
}
Sujeet SumanPosted Oct 18, 2015, 3:06 PM
Sujeet SumanPosted Oct 18, 2015, 3:02 PM
David SmithPosted Oct 18, 2015, 2:56 PM
David SmithPosted Oct 18, 2015, 2:52 PM
findString("ba", "cccabcc"); //returns 3
findString("cat", "cacatcatc"); //returns 2
findString("ba", "ccccccc"); //returns -1
Sujeet SumanPosted Oct 18, 2015, 2:37 PM
Sujeet SumanPosted Oct 18, 2015, 2:26 PM
David SmithPosted Oct 18, 2015, 1:46 PM
i see "ab" in the input string, which is in another order "ab". But can be "ba".
Is that not a match set in any order?
Sujeet SumanPosted Oct 18, 2015, 1:35 PM
David SmithPosted Oct 18, 2015, 11:47 AM
Sujeet SumanPosted Oct 18, 2015, 8:59 AM