Timeline for Given an array of integers, return the smallest positive integer not in it
Current License: CC BY-SA 3.0
5 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Nov 2, 2017 at 13:41 | comment | added | lampshade |
You don't need to test all negative values actually. What I meant is: You have a while loop which runs in O(n) which uses in_array which is also O(n) so your time complexity is O(n^2) . Hope this makes sense.
|
|
Nov 2, 2017 at 13:31 | comment | added | Shaun Bebbers | @lampshade I have made amendments to the function above - now checks for a range of -1000000 to +1000000 inclusive. | |
Nov 2, 2017 at 13:28 | history | edited | Shaun Bebbers | CC BY-SA 3.0 |
Corrected the solution based on the prompts in the question above
|
Nov 2, 2017 at 11:00 | comment | added | lampshade |
I'd say that this is the same as the OP's code: This means it is O(n^2) instead of O(n) and does not fulfill the requirement of the question.
|
|
Nov 1, 2017 at 17:12 | history | answered | Shaun Bebbers | CC BY-SA 3.0 |