Google Interview Question for Software Engineer in Tests


Country: United States
Interview Type: In-Person




Comment hidden because of low score. Click to expand.
9
of 9 vote

Chi Square test, distribution test

- Ashupriya August 13, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

More specifically. Use it to generate 100000 samples. Evaluate the distribution of samples.

- majun8cn August 22, 2012 | Flag
Comment hidden because of low score. Click to expand.
8
of 12 vote

This is harder than it sounds. Just generating numbers and binning them will not work, because then this would be a valid random number generator:

unsigned int randVal = 0;

float rand() {
  randVal++;
  return randVal / (float)INT_MAX;
}

- Martin August 09, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
3
of 3 vote

.johndcook.com /Beautiful_Testing_ch10.pdf

- Anonymous August 22, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

monte carlo simulation.

- Joe August 20, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

+1, use monte carlo algorithm,e.g. for pi computation

- 111 March 10, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 2 vote

print the numbers into a file and try to compress using e.g. Zip/huffman. Random set should be impossible to compress

- leofer August 21, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I think none of the solution is efficient.
I was wondering if this can be solved by following various criteria:
1) Test How Georgi Kalchev suggested
2) Do a Chi Square Test
3) Try XORing all numbers?

- Andy2000 August 26, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I think none of the solution is efficient.
I was wondering if this can be solved by following various criteria:
1) Test How Georgi Kalchev suggested
2) Do a Chi Square Test
3) Try XORing all numbers?

- Andy2000 August 26, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

take 100000 entries
assume that the range in which the random number are being generated is between minimum and maximum (can be assumed for large entries)
Now, for each position, count the number of times the next number appearing after it is more than it or not. Take this ratio. This ratio should be proportioinal to the (Max - E)/(Max-Min)
where E is the current value
Now, plotting these values for all positions, we take the variance. If the variance is small, then the random number generator can be assumed good

- Dubey August 29, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Hi ,

What if we use time to generate the randon number. Get the current time in milliseconds and divide it by 1000.

class TimeTest{
		public static void main(Strings[] args){
			system.out.println(System.currentTimeMilliseconds()/1000);
		}
	}

This should generate unique number definetly.


Regards,
Vijay Kalkundri

- vvk March 16, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 5 vote

Generate random numbers in large range and plot the random numbers in a graph which should be a uniform distribution for all the numbers in the range.

- sachin.irukula August 09, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

@sachin.irukula What if the number sequence is wrapped around increasing, i..e. 1,2,3,4,5,6,7... 1,2,3,4,5,6,7... you have uniform distribution.

- Daru August 11, 2012 | Flag
Comment hidden because of low score. Click to expand.
-1
of 1 vote

1.) we can check how the elements distribute over a given range
2.) we can check how many times one number is hit and what is the difference between the most hit number and the least hit one.
3.) *Visually check for patterns of each number hits by looking (in the code bellow I would look) the "map".

point 1.) sample Java code:

public static double randPercent() {
  int N = 1000;
  int[] map = new int[N];
  int cnt = 0;

  int rand;
  for (int i = 0; i < N; i++) {
   rand = (int) (Math.random() * N);
   map[rand]++;
 
   if (map[rand] == 0)
    cnt++;
  }
 
  //System.out.format("Result is %s (different numbers) out of %s", cnt, N);
 
  return (double) cnt / N;
 }

- GKalchev August 09, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

This is just one of the many tests you need to do. See Martin's response for one (out of many possible) examples of why your approach is woefully insufficient.

Some additional tests would be making sure there's no correlation between one number and the next, checking longest runs of ones and zeros, checking criteria like dimensional equi-distribution, and a zillion and one other tests. You can read about all of these on the Internet. This is a very nontrivial problem.

- eugene.yarovoi August 09, 2012 | Flag
Comment hidden because of low score. Click to expand.
-1
of 1 vote

None of the solution above really works.
Think about this fake random number generator.

static n = 0;
void fakerand()
{
n++;
if(n%2==0)
return rand()*0.5;
else
return 1-(rand()*0.5);
}

We need to generate a really long sequence. And try to proof, as much as we can, that there is no pattern in this sequence.

- LoocalVinci August 10, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

What is rand()? And what am I supposed to think about when thinking about this?

- eugene.yarovoi August 10, 2012 | Flag
Comment hidden because of low score. Click to expand.


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More