Algorithm to determine if array contains n…n+m?

前端 未结 30 3123
清酒与你
清酒与你 2020-11-28 01:45

I saw this question on Reddit, and there were no positive solutions presented, and I thought it would be a perfect question to ask here. This was in a thread about interview

30条回答
  •  旧巷少年郎
    2020-11-28 02:01

    note: this comment is based on the original text of the question (it has been corrected since)

    If the question is posed exactly as written above (and it is not just a typo) and for array of size n the function should return (True/False) if the array consists of the numbers 1...n+1,

    ... then the answer will always be false because the array with all the numbers 1...n+1 will be of size n+1 and not n. hence the question can be answered in O(1). :)

提交回复
热议问题