Input Q: Why "foobarfoothefoobarman" ["foo","bar"] => [0,3,12] instead of [0,6,12]

  • 0

    I try to understand the questions.
    says, input is "foobarfoothefoobarman" ["foo","bar"]
    why the input is [0,3,12] instead of [0,6,12]

  • 1
    Hello Hirakawa,
    It is because the order of words is not important:
    Starting at index 0, we have foobar
    Starting at index 3, we have barfoo
    Starting at index 6, we have just foo (not followed by bar)
    Starting at index 12 we have foobar again.
    Hence the output is [0,3,12] and not [0,6,12].
    I hope it helps.

  • 0

    Hence the output is [0,3,12] and not [0,6,12].

Log in to reply

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