Pathological data set???

  • 1

    Input: [1,2,3], [2,5,6]
    Output: [1,0,0,0,0,0]
    Expected: [1,2,2,3,5,6]

    My code fails with this error. However the guidelines explicitly state:

    You may assume that A has enough space (size that is greater or equal to m + n) to hold additional elements from B. The number of elements initialized in A and B are m and n respectively.

    In this case I would have expected input to be something like:

    Input: [1,2,3,null,null,null], [2,5,6]

  • 0

    One other nuance, not stated by requirements: the data may contain duplicated values. In most "textbook examples" of merge, this is not the case.

    So JFYI, might submit your code a few times only to realize this detail was omitted.

  • 0

    The rest of A is simply not shown since it is just a waste of display space, but there is indeed more allocated memory there than what you can see. Apparently, the expected result is not caused by lack of space, but by the fault of the logic of your code, or maybe a simple bug. You may want to manually go through the code and see what it happens in there.

  • 0

    int is a primitive type and cannot be null. How are we supposed to know which spaces in array A are "free"?

Log in to reply

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