Expected output "" for input ["ca", "a"]?


  • 0
    R

    Hi, my solution got wrong answer for this test and I can't figure out why, shouldn't the output be "a" ?

    Input: ["ca","a"]
    Output: "a"
    Expected: ""

    Thanks in advance.


  • 2
    M

    What you are looking for is the longest common prefix. In other words, the longest substring the strings start with in common. While "a" is the longest common substring, "ca" does not start with "a", so it cannot be a prefix, and therefore cannot be the correct answer.

    Since one starts with 'c' and the other starts with 'a', only the empty string at the start is in common to the two strings provided.


Log in to reply
 

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