Code Coach - Word Rank. Please see my code. It failed all the test cases. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Code Coach - Word Rank. Please see my code. It failed all the test cases.

Hello. This is the instruction > Input is a string (word) representing a sequence of letters ( A - Z ). It can contain duplicate letters. Rearranging the letters in the word, you can come up with new words composed of the same letters. The output is an integer representing the rank of the inputted word ( sorted alphabetically ). My code failed all the test cases. It hangs up when a long word is being inputted. I hope someone can give me a hint so that I can revise my code. Thank you. https://code.sololearn.com/c3hbuw6yJwm6/?ref=app https://code.sololearn.com/c3hbuw6yJwm6/?ref=app

25th Sep 2022, 9:06 AM
Cris Tradio
Cris Tradio - avatar
5 Answers
+ 5
Cris Tradio , they don't want to see the index number of the "input word" in the list, they wanted to see the rank. see the explanation / sample table in the task description. . an other thing is that the list of possible words coming from permutations has a lot of dupicates. use set() to remove them before further processing. as it is difficult to describe some other issues in the code, i have decided to use your code and keep it as close as possible (normally we should not give a ready code - sorry) i will attach this code later.
25th Sep 2022, 10:03 AM
Lothar
Lothar - avatar
25th Sep 2022, 10:50 AM
Lothar
Lothar - avatar
+ 1
Hi Lothar, it's ok if there's no ready code. I just want a suggestion and I will figure it out myself. I want to learn...I really appreciated your reply and your suggestion. Thank you.
25th Sep 2022, 3:55 PM
Cris Tradio
Cris Tradio - avatar
+ 1
Hi Lothar, I already revised the code. Based on your suggestion, I found out that "set" runs the program faster compared to "list comprehension" in removing the duplicates in permutations, especially for longer words. I still used the index in the output but I added 1. The code passed all the test cases. Thank you for the additional knowledge.
25th Sep 2022, 4:50 PM
Cris Tradio
Cris Tradio - avatar
0
Thank you Lothar!
25th Sep 2022, 9:47 AM
Cris Tradio
Cris Tradio - avatar