wrong answer by judge

  • 9

    I think there is a temporary glitch in the system. Anybody from the admin team could please look at the issue. Here is the screen shot of showing the wrong answer of the given example:0_1487056716578_Screen Shot 2017-02-13 at 11.12.08 PM.png

  • 0

    Seems to work fine for me?

  • 2

    I still see the same thing0_1487105486161_Screen Shot 2017-02-14 at 12.50.40 PM.png :

  • 2

    2::Each transformed word must exist in the word list. Note that beginWord is not a transformed word.
    end:"cog" is not find in wordlist

  • 0

    Oh yeah didn't notice that. @yubb is right.

  • 0

    @towhid same problem happens to me. The test case might mean to check if we can give quick answer if endWord is not in the dictionary.

    Add this code at front to pass that one:

        if endWord not in wordList:
            return 0

    Here is my sample solution:

    def ladderLength(self, beginWord, endWord, wordList):                
        if endWord not in wordList:
            return 0
        begin_set, end_set = set([beginWord]), set([endWord])
        wordSet = set(wordList)
        length = 1
        alphabets = list(map(chr, range(ord('a'), ord('z')+1)))
        while begin_set:
            # find all possible one-change words in the wordList
            begin_set = wordSet & set(word[:idx] + char + word[idx+1:]  for word in begin_set for idx in range(len(beginWord)) for char in alphabets)
            if begin_set & end_set:
                # if there are common word in next_level and end_set
                return length + 1
            length += 1
            # always proceed on the smaller set
            if len(begin_set) > len(end_set):
                begin_set, end_set = end_set, begin_set
            # remove from wordList all the visted words in next_level, so as to avoid revisiting
            wordSet -= begin_set
        return 0

  • 0

    @StevenYU nice guess, haha! but i still think something is not proper with this case.

  • 0

    @iwantgoogle Yeah there's something wrong

    Here's the transform sequence
    hit, hot, dot, dog, cog (5)

    But I get expected = 0;

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.