Akamai Interview Question for Software Engineer / Developers


Country: India
Interview Type: In-Person




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

switch(rand(3))
case 1:
rand(3)
case 2:
3 + rand(3)
case 3:
6 + rand(3)

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

Super!

- Anonymous August 12, 2012 | Flag
Comment hidden because of low score. Click to expand.
2
of 6 vote

return (3*rand(3) + rand(3) -3)

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

Like

- jiangok2006 August 11, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

why do we need rand(3) -3 in the statement return (3*rand(3) + rand(3) -3)?????

isnt 3*rand(3) sufficient???

- codingAddicted August 11, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

3*rand(3) will not give 1 and 2.

- kunal.id89 August 11, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

3*rand(3) gives you 3 possibilities:
(3*1), (3*2) or (3*3)
=
3, 6, or 9

3*rand(3) - 3 gives you 3 possibilities:
(3-3), (6-3), (9-3)
=
0, 3, 6

3*rand(3)+rand(3)-3 gives you 9 possibilities:
(0+1), (0+2), (0+3), (3+1), (3+2), (3+3), (6+1), (6+2), (6+3)
in other words
1, 2, 3, 4, 5, 6, 7, 8, 9

Checks out.

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

Define a 3x3 matrix called A. Assign a value in range [1...9] to each entry of the matrix. Call rand(3) twice, and call the results i and j. Return the value corresponding to A[i][j]. Each outcome has probability 1/9.

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

Like

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

public static int Rand_3(){
return (int)(Math.random()*3)+1;
}
public static int Rand_9(){
return (Rand_3()*3)-(Rand_3()-1);
}

- Chengyun Zuo August 13, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 2 vote

no_of_times = rand(3);
if(no_of_times == 1){
    return rand(3);
}
else if(no_of_times == 2){
    return rand(3) + rand(3);
}
else{
    return rand(3) + rand(3) + rand(3);
}

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

in any case: 3 can be generated.
3
2,1
1,1,1

however 9 can only be generated for the last case like 3,3,3
the chance to generate 9 is (1/3)^3 = 1/27

The chance to generate 3 is
1/3+2/27+1/27=4/9

- Vincent August 10, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

(rand(3) -1)*3 + (rand(3) - 1)*1 + 1
Do it as you would generate a number in base 3 number.

Example:
Just for the example lets say rand(3) generates numbers 0,1,2 and we are looking form numbers from 0-8 (rand(9)). In base 3 system the max number with length 2 will be 22 = 2*3^1 + 2*3^0 = 2*3 + 2*1 = 8 (eq1). So we just do generate the number in base 3 and find what it is:
in eq1 we change the numbers: rand(9) = rand(3)*3 + rand(3)*1

so now changing rand(3) return 1-3, and rand(9) must return 1-9
and final equation is: rand(9) = (rand(3) -1)*3 + (rand(3) - 1)*1 + 1

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

the solution will need to call the function random(3) 2 times......
first divide numbers from 1 to 9 into three equal size buffers......1-3...4-6....7-9.
Each buffer is containing exactly 3 numbers.
Now write the function random(9) as:
int random(9)
{
int bufferNo=random(3);
// if bufferNo=1,choose first else if 2 choose buffer 2 else choose buffer 3.
// again call random(3) to choose number in the chosen buffer and return that number
}

- chandan prakash August 11, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Basically we are looking for :
{1,2,3} + 3*0 = {1,2,3}
{1,2,3} + 3*1 = {4,5,6}
{1,2,3} + 3*2 = {7,8,9}

Soln : RAND(3) + 3 * (RAND(3) - 1)

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

why not rand(3)+rand(3)+rand(3)

- rv May 05, 2014 | 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