Ad
  • Default User Avatar

    i have similar problem on python

  • Default User Avatar

    If you obtain all words from "", you will have an empty list, "" is not included.
    Otherwise, the most frequent word in any string would be "" (or would you suddenly change your logic for that? be consistent.)
    Looking through Haskell solutions, every single one includes a literal empty-list literal because that is nowhere to be found in the input itself.

    It isn't possible to return the maximum word out of zero words. This is undefined. Don't test for it.

    Attempting to obtain the maximum word out of no words is a bug.

    This is some kind of javaism of pretending null is acceptable. It's not. Not in java either.

    At most I would accept that, yes, the input is valid, but the output is undefined, so any response, including crashing, is valid.
    (But I'd rather stick to that if the input has no defined output then the input is therefore not valid, it's wrong to expect a result for it)

    What is the average word length of ""?
    If there's a word in that, how many words are there then in "tree"? 1? 2? infinite?

    Or are we going for that words are separated by space, that the number of words in a string is the number of spaces plus one? ie that " " is two words and

    "  "
    

    is three words

    But now we run into the issue of not being able to represent an empty string, because there's always at least one word in it. It's like removing 0 from our counting system.
    Adding a word to "" now means that there are two words, and that it has to have a leading space: "" + "tree" -> " tree", or rather, it doesn't have a leading space at all because there's a word first which takes zero space (should we really recognize something that takes zero space as counting as a word? I think that sounds wrong. If something takes zero space then it is not there)

    Also, if I slice an empty string, and don't include anything, then just the same I would have a word in my result.

  • Custom User Avatar

    No, you're right it's not obvious. I tried to defend this point of view because it's not explicitely stated in the rules that you must have at least one word, but it's definitely not obvious.

  • Custom User Avatar

    1 - Which language? Most don't check that case, but the answer is that you should obviously answer the best scoring word, which is ""
    2 - The description says All inputs are valid, namely a string containing only spaces and lowercase letters. There is no explicit specification on the number of words, so "", " " and such are edge cases, not invalid inputs (It indeed contains only spaces and letters)

  • Custom User Avatar

    It would help if you mentioned which language has this problem.

    It would also help if you could determine what the actual argument was that's giving you trouble - but the problem might be in the generating of the random argument or the processing of it; in the first case you'll never getit of course.