+ 2
Isogram detector challenge solution issue?
I can't for the life of me work out why the attached C++ code fails on the Isogram challenge. Specifically on the fourth test case, which is hidden so I can't get any additional debug feedback unfortunately. Any help would be appreciated! https://code.sololearn.com/cliMCF4jCRKU/?ref=app
4 Respuestas
+ 3
Your copying of word into uniqueLetters in the loop ll.15-21 doesn't work because uniqueLetters is not initialised with any capacity. Eventually, if input is long enough, the program will crash.
You don't need to copy this complicated. Just init uniqueLetters with word:
string uniqueLetters { word };
And get the length of word directly:
size_t wordLength = word.length();
+ 1
Thanks for your time answering!
From that though, I would have thought that if the loop copying the letters of word into uniqueLetters wasn't working all the test cases would have failed? Rather than only one of them?
Although it's a good point about the undefined size creating a potential issue, a safe guard would need to be put in for that.
As to the .length() approach, I am trying to code it withour using that, as a way to try and improve my ability to find solutions. Sounds somewhat silly, I know, but I like a challenge!
0
That is quite all right :) About the crashing, the string is somewhere in memory. As you copy data, you will overwrite memory, perhaps not used memory, who knows. It is not possible to say when something is going to happen, but the more memory you overwrite, the more likely that you overwrite something that is needed, perhaps even vital.
0
So, I am still getting an error. 4 of the test cases still pass (1,2,3,5), but for some reason the 4th test case doesn't. This will drive me crazy I swear lol.