Two Strings

Given two strings of equal length, you have to tell whether they both strings are identical.

Two strings S1 and S2 are said to be identical, if any of the permutation of string S1 is equal to the string S2. See Sample explanation for more details.

Example:

Input:  a = "sumit", b = "mitsu"
Output: YES

Approach

C++

#include <bits/stdc++.h>
using namespace std;

void twoStrings(string astring b)
{
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    if (a == b)
        cout << "YES\n";
    else
        cout << "NO\n";
}
int main()
{

    string a = "sumit"b = "mitsu";

    twoStrings(ab);

    return 0;
}


No comments:

Post a Comment