//my solution in javascript function stray(numbers) { let a = numbers.sort((a,b)=>a-b) if (a[0] !== a[1]) return a[0] else { return a[a.length -1] } } stray([1, 1, 2])
That's a great work around.
Would you be able to do it in O(n) time? numbers.sort usually be O(n log n) (unless using TimSort and data is already sorted).
O(n)
numbers.sort
O(n log n)
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
That's a great work around.
Would you be able to do it in
O(n)
time?numbers.sort
usually beO(n log n)
(unless using TimSort and data is already sorted).