What does my test case not generating expected output from accepted code?


  • 0
    Z

    While I was trying to make sense of the accepted code posted in here, I found out that the code does not work for this test case. Am I understanding the question wrong?

    int A[4] = { 3,4,1,2};
    int* B = A + 2;
    
    sol.merge(A,2 ,B, 2);
    

    Expected output: 1,2,3,4
    Execution result: 3,4,4,4


  • 0
    S

    Because B is part of A, it will mess up when passing into merge function.

    I guess, this way

    int A[4] = { 3,4,1,2};  // 1, 2 can be random number
    int B[2] = { 1, 2} ;
    

    should be fine.


  • 0
    Z

    Should not B be a part of A though?


  • 0
    S

    It might be OK. It depends on what the solution looks like.


Log in to reply
 

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