Can someone EXPLAIN the question to me?


  • 0
    I

    Assuming you've read the problem:
    I coded up an answer, then ran test cases, only to find:

    Input:
    String s: "barfoofoobarthefoobarman"
    String[] words: ["bar","foo","the"]

    My Output:
    [0,3,6,9,12,15]

    Expected:
    [6,9,12]

    "barfoo" in String s starting at index 0 is a concatenation of
    "bar" and "foo" in String[] words
    so why is index 0 not part of the correct (Expected) answer?

    So my algorithm didn't address the question, meaning I didn't understand the problem!

    Simply, my algorithm is,

    if current (first) substring of length 3 is inside String[] words,
    check if the next substring of length 3 is also in words.

    save current (first) index of substring


Log in to reply
 

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