Closed TFloyd1989 closed 3 years ago
The new announcement if for those who accidentally concatenate the string up to the root (which is null) and return as a list. In this way, only by asserting can they find the error, and simply printing won't help.
In your case, it seems that the logic is correct, but
(1) It seems that you did not trim the word with there is a whitespace (2) what will you get when you simply use "she" as your prefix? From my end, there are exceptions in your output.
I trim the word earlier in my code in line 35 if the string is not blank, and I used the prefix she while testing which never gave me any errors.
This is the output for she with no changes to my code
May I know what does that 's}' represent? Also, could you drag it a bit more or paste it here so that I can see the whole return list?
Oh, I see, the 's}' is your candidate, could you please share all the output then?
Here are all of the tests and results
(All testing done with original code)
Could you please try changing your candidate to null and see what happened?
I get a null pointer exception
When testing your code with null as candidate, this is what I get
So according to textbook you did not deal with followings:
Your program should be able to handle prefixes or candidates that do not exist in the dictionary.
All picked candidates should be introduced as real words to the trie.
Whitespaces are not allowed as input; thus, you should trim all input strings.
Understood, is this where I lost a lot of points?
Yes, you may want to fix that error within two lines of code change before 1pm
We are only allowed to modify 2 lines in the total code?
You don't need to insert null into this. For a null candidate, you just return the candidates for the prefix as usual and it should be solved with 1 line.
Yes, in total, 2 lines at most
For example, if a given candidate sh has the candidates shell and sheep, getcandidates should return shell and sheep if pickcandidates contains null? Also, what if sh has no candidates at all?
I was just wondering if I concatenate the null character in my code. If the prefix is empty, I make the prefix equal to an empty space "" which I then get the children of. I'm pretty sure this is the root node. For the first iteration of my BFS, I do prefix + key in a loop, which I think concatenates the root character. I have also included a screenshot.