There is a test task, I'm a little hooked in the algorithms, I can tell what the best fit for the task?

There is an array of numbers from 1 to 100000000000. The array is sorted(1,2,3 ....99999999999,100000000000 ), but in this one figure has Sadorus(E.g. [1,2,3,4,4,6,7 ...]). I need to write a method that will find the missing number in minimal time.
June 5th 19 at 21:49
1 answer
June 5th 19 at 21:51
Solution
In the "correct" sequence of numbers the sum of each pair of numbers, if you take the head and tail does not change. To get to the place where they mixed up the numbers by brute force you will need N/2, and still need to figure out which of the two numbers is wrong, for example by checking its neighbors

The second problem you need to break text into tokens
str = "Hello I'm your String";
String[] splited = str.split("\\s+");

https://stackoverflow.com/questions/7899525/how-to...
and then iterate through the array and give every third word. The question still is what to do with punctuation marks which are usually attached to a word. In mind they need to discard.
The first is solved in log N and not N/2 - annie_Pagac commented on June 5th 19 at 21:54
for the first task, not podskazhiet how to declare long array? - ulises_King69 commented on June 5th 19 at 21:57
this statement that I can't check, explain your algorithm. - Jeanie_Torphy90 commented on June 5th 19 at 22:00
and all read above, I agree. - Jeanie_Torphy90 commented on June 5th 19 at 22:03
it would be barbarity to deprive You of the opportunity to learn it yourself. Any basic tutorial in Java will put you on the right answer. - Jeanie_Torphy90 commented on June 5th 19 at 22:06
just a hint?) you should use BigInteger? - ulises_King69 commented on June 5th 19 at 22:09
, long []; BigInteger has a greater range than long. - Jeanie_Torphy90 commented on June 5th 19 at 22:12
okay then I will look for, but in java not ustravivaet long array[] = new long[100000000l] - ulises_King69 commented on June 5th 19 at 22:15
Java does not support arrays larger than MAXINT. ie, the dimension expected of type int.
Remove the l in the dimension, or add caste long[(int)100000000l] automatic type conversion in this case does not work due to possible loss of precision.
If the desired array is very big you will have to use data structures of type ArrayList - Jeanie_Torphy90 commented on June 5th 19 at 22:18
thank you) - ulises_King69 commented on June 5th 19 at 22:21

Find more questions by tags JavaAlgorithms