wrong answer by judge


  • 10
    T

    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
    D

    Seems to work fine for me?


  • 2
    T

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


  • 2
    Y

    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
    D

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


  • 0
    S

    @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
    I

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


  • 0
    B

    @iwantgoogle Yeah there's something wrong

    "hit"
    "cog"
    ["hot","dot","dog","lot","log"]
    Here's the transform sequence
    hit, hot, dot, dog, cog (5)

    But I get expected = 0;


  • 0
    S

    It's been a few months since the last post and I still see this test case failing. As @brichards pointed out, transformation is possible from "hit" -> "cog" with the sequence provided. The word list contains intermediate words allowed during the transform and doesn't have to include the end word. How can we get this fixed?


Log in to reply
 

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