Retired
First duplicate in Array (retired)
Loading description...
Algorithms
Arrays
Data Types
Lists
Data Structures
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
A classical question for an interview job and very important to know it. Unfortunately it's a duplicate of a kata previously published: https://www.codewars.com/kata/find-the-duplicated-number-in-a-consecutive-unsorted-list-tougher-version
And many others with very similar.
Description specifies two different rules for which duplicate to return. The second is wrong.
Returning
-1
is not a good choice. It might be a valid return value as well ( you never specify that the array only contains nonnegative numbers ).undefined
or in this case maybeNaN
(!) might have been better choices, if you don't want to throw anError
.map[] === true
( in the reference solution ) is a bit of an antipattern, isn't it? It's aBoolean
already.