5 kyu
Find number in an array # 1
79 of 130myjinxin2015
Description:
When no more interesting kata can be resolved, I just choose to create the new kata, to solve their own, to enjoy the process --myjinxin2015 said
Description:
Given an unsorted array arr
that contains some positive integers. It may be one of the following:
1. There are numbers 1 to n, only one number is
duplicate(repeated two times), the other numbers are unique.
That is, there are n+1 elements in the array.
e.g. [1,2,3,6,5,4,1]
2. There are numbers 1 to n, only one number is
unique, the other numbers are repeated two times.
That is, there are 2*n-1 elements in the array.
e.g. [1,2,3,1,2,3,4]
Your task is to determine the type of the array, if it is the first type, to return the duplicate; if it is second type, return the unique.
Note:
- All numbers are positive integers that from 1 to n;
- The length of array always more than 5;
- Please pay attention to optimizing the code to avoid time out.
Some Examples
input output
[1,2,3,6,5,4,1] 1
[1,2,3,1,2,3,4] 4
[3,6,9,2,5,8,1,4,8,7] 8
[9,8,7,1,2,3,9,7,1,2,3,4,4,5,5,6,6] 8
Algorithms
Puzzles
Similar Kata:
Stats:
Created | Nov 30, 2016 |
Published | Dec 1, 2016 |
Warriors Trained | 629 |
Total Skips | 23 |
Total Code Submissions | 4074 |
Total Times Completed | 130 |
JavaScript Completions | 79 |
Python Completions | 53 |
Total Stars | 32 |
% of votes with a positive feedback rating | 90% of 46 |
Total "Very Satisfied" Votes | 39 |
Total "Somewhat Satisfied" Votes | 5 |
Total "Not Satisfied" Votes | 2 |
Total Rank Assessments | 7 |
Average Assessed Rank | 5 kyu |
Highest Assessed Rank | 4 kyu |
Lowest Assessed Rank | 6 kyu |