Raytheon Interview Question for Software Engineer / Developers


Team: Speech Recognition
Country: United States
Interview Type: Phone Interview




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

car A in 10 simulation will move 1 time ==> 5feet
car B in 10 simulation will move 6 time ==>1X6 ==> 6feet

so in 100 simulation :
Car A : 50 feet ;Car B :60 feet

so,mathematically car B have more chance to win the race. we know that when no. of experiment increases then outcome automatically get more aligned toward the mathematical output(drawn from probability).
here 100 is a large no. so we can say Car B will win and result will me according to mathematical analysis.

- Ali_BABA November 06, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.Random;
   public class CarRace {
       
    public void raceCars(){
                int carA=0;
                int carB=0;
                int carAchance=0;
                int carBchance=0;
 
                Random rand = new Random();
 
                for(int i=0;i<100;i++){
                                carA = 0;
                                carB = 0;
                               
                         while(carA !=100 && carB!=100) {
 
                                         if(rand.nextInt(100) < 10){
                                                    carA=carA+5;
                                                    }
                                         if(rand.nextInt(100) < 60){
                                                    carB=carB+1;
                                                    }
                                }
                               
                                if(carA == 100){
                                                    carAchance++;
                                 }
 
                                if(carB == 100){
                                                    carBchance++;
                                }
            
          
                 if(carA>carB){
                                 System.out.print("car A won \n");
                }
                else if(carA<carB){
                                System.out.print("car B won \n");
                }
                else if(carA == carB){
                                System.out.print("Both won equal number of times ");
                }
                }
}
 
 
public static void main(String args[]){
 
        CarRace race = new CarRace();
        race.raceCars();
 
}
 
}

- teja.sbt November 06, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Expectations: In a perfect world, every turn, car A goes .5 feet and car B goes .6 feet

Hypothesis: Car B will win the majority.

Outcome: B always won, over 76% of the time. Generally at least one tie.

Over 10,000 iterations, the 76% holds true.

<?php

function car_sim()
{
	$turn = $car_a_feet = $car_b_feet = 0;

	while (1) // Infinite Loop FTW!
	{
		$turn++;

		// Car A and B attempts to move
		$car_a_feet += rand(0,9) == 9 ? 5 : 0;
		$car_b_feet += rand(0,9) >= 4 ? 1 : 0;

		// Has anyone won?
		$winner = FALSE;
		if ($car_a_feet >= 100 && $car_b_feet >= 100)
			$winner = 'TIE';
		elseif ($car_a_feet >= 100)
			$winner = 'A';
		elseif ($car_b_feet >= 100)
			$winner = 'B';

		if ($winner !== FALSE)
			return array($winner, $turn);
	}
}

$race_analysis = $winner_analysis = array();
foreach (range(0,99) as $race)
{
	list($winner, $turn) = car_sim();

	$race_analysis[$race] = $winner . ' in ' . $turn . ' turns';
	@$winner_analysis[$winner]++;
}

var_dump($winner_analysis, $race_analysis);

- tickthokk November 06, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

The expected move for Car A in x runs of simulation is: x*0.1*5 = 0.5x
The expected move for Car B in x runs of simulation is: x*0.6*1 = 0.6x

so after x runs it is expected CarB to move further than CarA.

The code in Java.

public static void main(String[] arg)
	{
		int carAWon=0;
		int carBWon=0;
		int tie=0;
		
		for(int k=0; k<100; k++)
		{
			int sumA=0;
			int sumB=0;
					
			while(sumA<100 && sumB<100)
			{
				double randomNumber=Math.random();
				
				if(randomNumber<=0.1)
				{
					sumA+=5;
				}
				
				if(randomNumber<=0.6)
				{
					sumB+=1;
				}
			}
			
			if(sumA>sumB)
			{
				carAWon+=1;
			}
			else if(sumA<sumB)
			{
				carBWon+=1;
			}
			else
			{
				tie+=1;
			}
				
		}
		System.out.println("Car A Won: "+carAWon);
		System.out.println("Car B Won: "+carBWon);
		System.out.println("Tie: "+tie);
	}

Sample outputs:
run1: Car A Won: 21, Car B Won: 77, Tie: 2
run2: Car A Won: 22, Car B Won: 78, Tie: 0
run3: Car A Won: 26, Car B Won: 73, Tie: 1

- Alirz January 28, 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