diff --git a/DSA Essentials Solutions/Strings/ArePermutation.cpp b/DSA Essentials Solutions/Strings/ArePermutation.cpp index ed3a988..95da428 100644 --- a/DSA Essentials Solutions/Strings/ArePermutation.cpp +++ b/DSA Essentials Solutions/Strings/ArePermutation.cpp @@ -5,25 +5,23 @@ #include using namespace std; -bool arePermutation(string str1, string str2) + const int MAX_CHAR = 26; +bool arePermutation(string A, string B) { - // Get lenghts of both strings - int n1 = str1.length(); - int n2 = str2.length(); + // your code goes here + int countA[MAX_CHAR] = {0}; + int countB[MAX_CHAR] = {0}; + int l1 = A.length(), l2 = B.length(); + + for(int i=0; i1 && countB[i] == 0)) + return false; - // If length of both strings is not same, - // then they cannot be Permutation - if (n1 != n2) - return false; - - // Sort both strings - sort(str1.begin(), str1.end()); - sort(str2.begin(), str2.end()); - - // Compare sorted strings - for (int i = 0; i < n1; i++) - if (str1[i] != str2[i]) - return false; - - return true; -} \ No newline at end of file + return true; +}