Why the accepted programs can't get correct answer for two cases?


  • 0
    A

    when considering the problem, I write several cases to test before submit. After some trying, finally I gave up, and decided to see other peoples' idea. Then I see some claimed AC program, yes, they did got AC on leetcode, and I understand the algorithm behind them. But could you guys tell why the following cases won't pass.

    {120,121,119,117,116,115}, // expect 118
    {8,7,5,4,9,12,11,10}       // expect 6
    

    the problem itself just stated unsorted integer array, and I think the two cases I list above is valid?

    The program I tested including these:

    "my c solution 4ms"

    "my short c solution o(1) space and o(n) time"


  • 1

    What do those programs return for those cases? And why do you expect 118 and 6 for them? The correct answer for both is 1.


  • 0
    A

    why should we expected 1 instead of 118 and 6? The problem does not say that the the values should come from 1,2,3,..,n. Ok, I see you point. My misunderstanding originate from how I understand 'miss', I take it as first positive integer missed in a consecutive serie.


  • 0
    C

    Your understanding is not bad, while it maybe not the expectation of this question.


Log in to reply
 

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