Why "1234"/"0111" returns 0A1B, but "1122"/"2211" returns 0A4B?

  • 1

    If the 2nd and 3rd "1" got ignored in the test case "1234"/"0111", the 2nd "2" and the 2nd "1" should be ignored in the test case "1122"/"2211" too, so its result should be 0A2B.

    Did I understand the expected behavior wrong?

  • 2

    I share the same confusion. IMHO, the question is not well described. Character in guess string is first matched to the same position character in secret string. If they don't match, then the character in guess string is matched to the leftmost same character in secret string. No matter it's "same position" match, or "left most" match, after matching, they disappear. So you 2nd and 3rd "1" cannot match anything because the 1st "1" matches "1". However, 2nd "2" and 2nd "1" in "2211" can indeed match something.

Log in to reply

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