what is the time complexity with BFS solutions (Java) ?


  • 0
    K
    1. Going through queue or words
    2. for each word, replacing the character from 'a' - 'z' is O(N2) loop
    3. within each of the above loop if we are using toCharArray and then after replacing the character in the word, we again create a new string out of this char array to form a new word and check this agains the set. So should we add time complexity of O(N) within the O(n2) loop as mentioned in step2 ?

    Could someone please explain the time complexity ?


Log in to reply
 

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