Inspired From YouTube Comments

I have a text file which contains numbers from 1 1 to 100 , 000 100,000 inclusive, but exactly one of the number is missing.

What is the missing number?


The answer is 77777.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

9 solutions

Aryan Gaikwad
Mar 28, 2015
1
2
3
4
String num[] = read().replaceAll("\\s+","").split(",");
for(int i = 1; i <= num.length; i++)
    if(!(num[i-1].equals(Integer.toString(i))))
        System.out.println(i);

Execution time (apart from time taken to read the file) ~ 0.03 seconds

I used Python coding as follows:

 s = [1,2,3,4...] * copy the data of the file here.
 s = sorted(s)
 for i in range(len(s)):
        if int(s[i]) != i+1:
            print i+1
            break
Brock Brown
Mar 28, 2015

Python's set class makes it easy.

Python 2.7:

1
2
3
text = open('lots_of_numbers.txt').read()
numbers = set([int(n) for n in text.split(', ')])
print "Answer:", (set(range(1,100001))-numbers).pop()

Mauricio H
Aug 1, 2015

Javascript:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
var digitz = [0, 1, 2, 3, ...];
var i = 0;

while (i < 100000) {
    if (i != arr[i]) {
        document.write(arr[i] - 1);
        break;
    }
    i ++;
} 

Anik Mandal
Mar 29, 2015

Nit Jon
Dec 28, 2015

Pretty simple question. Just make an array with the numbers and then put it in a for loop with i = 0 to i=100000 and check if the indexes of the array match with the numbers. If not, then break. The answer turns out to be a simple 77777. Pretty simple, huh :)

class findNum {
    public static void main(String args[]) {
       String s = "1, 2, 3 ..."
       String[] arr = s.split(", ");
       int[] test = new int[100000];
       for (int i =0;i<arr.length;i++) {
         test[i] =  Integer.parseInt(arr[i]);
       }
       int answer = 0;
       for(int i = 0;i<100001;i++){
             if(test[i]!=(i+1)){
              answer = i+1;
              break;
             }
       }
       System.out.println(answer);
      } 

    }
Adarsh Shetty
Mar 28, 2015
  • using matlab
  • a=input('enter the numbers');
  • for i=1:99999
  • if(a(i)~=i)
  • disp(i);
  • break;
  • end
  • end

It's easy if you analyse a particular column in notepad. Before the missing number i.e 77777 all the entries in that column will be odd but after the number is missed, the subsequent entries have even number in the end. (Given that only one number is misplaced).

Sid 2108
Mar 28, 2015

The probability of the number being 77777 77777 was 1 100000 \frac{1}{100000} so there are changes that it might be 77777 77777 so I verified with 'Find' command and guess what I was RIGHT !!!!!!!!!!!

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...