Anagram String | Lexicographically Sorted

You are given n strings and you have to arrange anagram strings in separate line in order.
for example:

Input:

n = 7
aabbcc
acbabc
abccba
bcba
ab
aa
abbc

Output:

aa
aabbcc abccba acbabc
ab
abbc bcba

Explanation:
output strings in same lines are anagram in Lexicographically order also strings in different lines are also Lexicographically arranged.

I am trying to solve the problem but my code showing runtime error

here is my code: http://ideone.com/UoJmN0

please help

First, you have not given any input to your program on ideone.

Now, you are getting an RTE because of the way you are handling your vector of vectors.

Here is the modified code: http://ideone.com/wWqW0G

Notice, how I have commented out a few lines of code, and instead added the correct way, just beneath them. There are no other changes, and we get the output, as required.

PS: Looking at the program, I am deducing that each of the input words can contain only lowercase letters. If there can be uppercase letters also, you would need to modify your isAnagram function to incorporate them as well.

1 Like

Thanks tijoforyou

1 Like