## EMC Interview Question for Software Engineer / Developers

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

use random number generation; then %10; then 0~4 -> A, 5~8 -> B, 9 -> C

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

int method()
{
for(int i=1;i<=10;i++)
{
if(i<=4)return a;
elseif(i<=9)return b;
else return c;
}
}

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

hehe, wise guy

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

Given K discrete events with different probabilities P[k], produce a random value k consistent with its probability.

The obvious way to do this is to preprocess the probability list by generating a cumulative probability array with K+1 elements:

``````C[0] = 0
C[k+1] = C[k]+P[k].``````

Note that this construction produces C[K]=1. Now choose a uniform deviate u between 0 and 1, and find the value of k such that C[k] <= u < C[k+1]. Although this in principle requires of order \log K steps per random number generation, they are fast steps, and if you use something like \lfloor uK \rfloor as a starting point, you can often do pretty well.

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

``````char method()
{
int x=(int)Math.random*9;
if(x<=3)
return 'a';
if(x<=8)
return 'b';
return 'c';
}``````

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

``````char method()
{
int x=(int)Math.random()*9;
if(x<=3)
return 'a';
if(x<=8)
return 'b';
return 'c';
}``````

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

dude wht a dumass , after return the stack will be deallocated (google it)

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

you missed to see the if statement before return statement.

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

``````import java.util.Random;

/**
*
*/

/**
* @author Lazycoder
*
*/
public class Percentage {

/**
* @param args
*/
public static void main(String[] args) {
Random rand = new Random();
int i = rand.nextInt(10);
if(i < 4){
System.out.println("A");
}else if(i < 9){
System.out.println("B");
}else{
System.out.println("C");
}

}

}``````

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

``````int method()
{
return 40 % A, 50 % B && 10 % C
}``````

????

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

Haha awesome! :)

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

``````for(int i=1;i<=10;i++)
{
if (i<5) return 'A';
else if i(<9) return 'B';
else return return 'C';
}``````

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