+ 4

My First Challange: Input 2 Strings from user and Check,show appropriate message whether entered Strings are Anagram or NOT ?

Anagram Strings are those Strings which are equal in Number of Characters and every Character of 1 String is present in the other String exactly ones, position of Characters dosen't matter. Example: Str1 = abc Str2 = bca Strings are Anagram !! and please show the appropriate message regarding strings are Anagram or NOT nd Strings are equal or NOT if not equal don't resume and display appropriate message. good luck guys !!

22nd Aug 2017, 4:41 AM
Gaurav
Gaurav - avatar
25 Respuestas
22nd Aug 2017, 4:50 AM
Hatsy Rei
Hatsy Rei - avatar
22nd Aug 2017, 5:07 AM
P R
P R - avatar
+ 8
@Gaurav Please amend your original challenge to make it more descriptive as to what you require.
22nd Aug 2017, 6:05 AM
Hatsy Rei
Hatsy Rei - avatar
+ 7
@Gaurav "Fixed". Looking back at that code, it isn't the best algorithm. Code Playground input method also messed up the whitespace omitter. I think I'll submit another code later.
22nd Aug 2017, 5:36 AM
Hatsy Rei
Hatsy Rei - avatar
+ 6
@Gaurav Thanks for pointing that out. My 'later' fix is implemented. Transplanted a part of scrabble() to this code. :>
22nd Aug 2017, 5:52 AM
Hatsy Rei
Hatsy Rei - avatar
+ 4
@Gaurav I checked most people's codes, Yash Thatte's seems to have the best time complexity, ~O(2*n), at least for very long strings, David Ashton's has O(n!), which is probably the worst but I liked his concise two-line code 😃, and the rest are ~O(n*n), including yours I think but I'm not sure because yours is the most overly complicated that I didn't even dare to follow (I don't consider myself that good). Could you explain if there's any advantage that I missed to the overly complicated way that you employed?
26th Aug 2017, 3:56 AM
lion
lion - avatar
+ 4
My code just generates all the permutations of the letters in one of the words and if the other word is one of those, they are anagrams. As Lion said, this is a relatively slow method and really doesn't scale well. I think Yuri's code should be pretty fast, comparing the two words after their letters have been sorted.
26th Aug 2017, 7:37 AM
David Ashton
David Ashton - avatar
+ 3
Here is some Python Notice the code requests an input of 2 numbers separated by a space. https://code.sololearn.com/cz3Gth243eiV/?ref=app
22nd Aug 2017, 6:14 AM
David Ashton
David Ashton - avatar
+ 3
Here is my code guys..... Please let me know if i have any bug or any other problem... https://code.sololearn.com/cts1nDdO2WY3/?ref=app
23rd Aug 2017, 2:50 AM
Gaurav
Gaurav - avatar
+ 2
@Hasty i think you should check your code. it doesn't ask for user to input Strings... which is must to check whether entered Strings are Anagram or NOT.
22nd Aug 2017, 4:55 AM
Gaurav
Gaurav - avatar
+ 2
@Hasty , @ P R Nice try ... but your code has bugs... run your code and input " abb " as 1st String and " aab " as Second String... nd your code says Strings are Anagram/returns 1 (true). which is NOT correct.
22nd Aug 2017, 5:46 AM
Gaurav
Gaurav - avatar
+ 2
here you go: very similar to another challenge, so codes were already there :D php version https://code.sololearn.com/w3tlVO0YRSvu/#php and here there is c++ version https://code.sololearn.com/cgij8qZOXAkf/#cpp
22nd Aug 2017, 5:55 AM
Luca
Luca - avatar
+ 2
@Hasty please display appropriate messages... nd if strings are not equal in number of characters then display appropriate messags.
22nd Aug 2017, 6:04 AM
Gaurav
Gaurav - avatar
+ 2
@Gaurav i will fix code as soon as possible, but as long as I can see, no way to ask for user input in php in code playground, so just edit the 2 words at the beginning of the code... if I'm wrong, happy to learn how to ask for user input!
22nd Aug 2017, 6:08 AM
Luca
Luca - avatar
+ 2
that is why I like python: half a line code https://code.sololearn.com/c3Gi17TdSXMM/?ref=app
22nd Aug 2017, 7:40 AM
yuri
+ 2
@Yash your cods is very impressive
22nd Aug 2017, 4:03 PM
Gaurav
Gaurav - avatar
+ 2
@Lucas Now your code is better than ever.
23rd Aug 2017, 2:41 AM
Gaurav
Gaurav - avatar
+ 2
I want to to say to every coder to be more descriptive about their code and its output because we never know about the users, they can be from technical background but not always. for those who are not from technical background, it can be difficult for them to understand your code. As programmers we have keep in mind about the extreame users, they might be the users who are using computer for 2nd or 3rd time, so it will be difficult to understand or use for them.
23rd Aug 2017, 2:49 AM
Gaurav
Gaurav - avatar
+ 2
@lion i know my code is a bit complicated but is understandable . I used HashMap to store the found character along with its index. My emphasis was on Accuracy and not on speed thats why its time consuming. It would be helpful for me if any one can give me an advice on how do i speed up my program and make it less time consuming.
30th Aug 2017, 4:44 AM
Gaurav
Gaurav - avatar
+ 1
@Luca your php version code doesn't ask for user input .. please fix this.. and if strings are not equal in number of characters then it should display appropriate message rather than not Anagram.
22nd Aug 2017, 6:01 AM
Gaurav
Gaurav - avatar