Amazon Interview Question for Research Scientists


Country: United States
Interview Type: Phone Interview




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

In python

{{
from random import random, randint, sample

#Given an array, divide it into two parts for monte carlo simulations
#with 80% of them as training and the rest as testing.


#without with repeated elements
def monte_carlo_split_without(array):
train = sample(array,int(0.8*len(array)))
test = list(set(array)-set(train))
return train,test

#with with repeated elements
def monte_carlo_split_with(array):
train = []
test = []
for ar in array:
if random() > 0.8:
test.append(ar)
else:
train.append(ar)
return train,test

#testing
if __name__ == '__main__':
a = sample(range(1,1000),300)
b = [randint(1,1000) for i in range(0,300)]
train, test = monte_carlo_split_with(b)
print len(train)+len(test)
print float(len(train))/len(b)

train, test = monte_carlo_split_without(a)
print len(train)+len(test)
print float(len(train))/len(b)
}}

- Larry December 14, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Is there any other limitations?
In PHP:

function divide_input(array $input) { 

	$num_input = count($input); 

	$testing = array(); 

	$keys = array_rand($input, floor($num_input*0.2)); 
	foreach ($keys as $key) { 
		$testing[] = $input[$key]; 
		unset($input[$key]);
	}
	unset($key); 

	return array($input, $testing); 
}

- mistralay December 22, 2013 | Flag Reply


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