Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
This comment is hidden because it contains spoiler information about the solution
The problem states that the array has every integer from 1 to n exactly once except for some integer in between, which appears twice. The array that you're testing on doesn't fit this description (it has a 9 but no 6, for example), so the solution doesn't work.
I tried this with: arr = [1, 5, 7, 3, 2, 9, 2, 8]
And it returned 9 instead of 2 :/
Clever
This comment is hidden because it contains spoiler information about the solution
O(n²) instead of O(n).
gotcha.
...because that would have been an incorrect formula.
This comment is hidden because it contains spoiler information about the solution
this
is a reference to the instance ofNumber
on which you called the methodtimes
.This comment is hidden because it contains spoiler information about the solution
Who is "this" ?
Hardly ever?
This comment is hidden because it contains spoiler information about the solution
Not really sure, but I'd say there is undefined behavior. Some compilers may prefer to eval LHS first and increment
p
before testing the character. See, e.g., https://en.cppreference.com/w/c/language/eval_orderLoading more items...