Scrambled Letters

Rehan is a very intelligent student in his class and he has a small brother Areeb who is very naughty and always disturbs Rehan in his school projects. Recently Rehan has been working on his English project where he is making new meaningful words denoted by W out of alphabets but Areeb scrambles all letters or misplaces some of the letters or adds some of the new letters denoted by SW. Now Rehan is facing difficulty in forming the words again, your work is to help Rehan to check whether he can form those words back from the letters he has now.

Note: All letters in the given words may be in lowercase some in uppercase or some may contain both.

Example:

Input:  s = "caTS", t = "cats"
Output: TS

Approach

C++

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

string scrambledLetters(string sstring t)
{
    int n = s.size();
    int m = t.size();
    if (n != m)
        return "false";
    else
    {
        if (s == t)
            return "true";
        else
        {

            string ans = "";
            for (int i = 0i < ni++)
                if (s[i] != t[i])
                    ans += s[i];
            return ans;
        }
    }
}
int main()
{
    string s = "caTS"t = "cats";

    cout << scrambledLetters(st);

    return 0;
}


No comments:

Post a Comment