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 SumanRank #790 · 2.9K reputationPosted Oct 18, 2015, 11:02 AM EDT
Sujeet SumanRank #790 · 2.9K reputationPosted Oct 18, 2015, 4:59 AM EDT
David SmithRank #999 · 2K reputationPosted Oct 18, 2015, 7:47 AM EDT
Sujeet SumanRank #790 · 2.9K reputationPosted Oct 18, 2015, 9:35 AM EDT
David SmithRank #999 · 2K reputationPosted Oct 18, 2015, 9:46 AM EDT
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 SumanRank #790 · 2.9K reputationPosted Oct 18, 2015, 10:26 AM EDT
Sujeet SumanRank #790 · 2.9K reputationPosted Oct 18, 2015, 10:37 AM EDT
David SmithRank #999 · 2K reputationPosted Oct 18, 2015, 10:52 AM EDT
findString("ba", "cccabcc"); //returns 3
findString("cat", "cacatcatc"); //returns 2
findString("ba", "ccccccc"); //returns -1
David SmithRank #999 · 2K reputationPosted Oct 18, 2015, 10:56 AM EDT
Sujeet SumanRank #790 · 2.9K reputationPosted Oct 18, 2015, 11:06 AM EDT