I used the following approach:

- Starting from the first element of ransomNote, check if element 'i' in string ransomNote is present in string magazine
- If found, then copy the last element of string magazine at location given by "iterator p" and pop out the last element of string magazine
- If not found then you cannot construct the message, so just return false
- If you are able to iterate through all the elements of ransomNote then it implies that you can construct the message, so return true at the end.

bool Solution::canConstruct(string ransomNote, string magazine)

{

string::iterator p = magazine.begin();

```
for(unsigned int i = 0; i < ransomNote.size(); i++)
{
p = find(magazine.begin(), magazine.end(), ransomNote[i]);
if(p == magazine.end())
{
return false;
}
*p = magazine[magazine.size() - 1];
magazine.pop_back();
}
return true;
```

}