## Qualcomm Interview Question for Software Engineer in Tests

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

Can you please elaborate on this question? Bcoz What I am guessing is you are trying to tell that Build a 5x5 matrix from 1-25 where each row,column and diagonals have same sum? Am I right?

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

Could you explain the questions in further detail? I do not understand.

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

ALso can you please let me know how did you plan to use the recursion. I can not think of a way

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

ALso can you please let me know how did you plan to use the recursion. I can not think of a way

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

for filling an array without repeating random number:
int min=0;
int max=0;
for i 0 to 99
arrayname[i]= min + (int)(Math.random*(max-min+1))
min++;
max++;
rof

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

How do you prove your matrix is random ? In fact it is not !

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

For second question you can use random function and use time as seed to generatr 1 to 100 unique numbers check each time if you have already used that number...

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

srand(time(?)) will help u to get different (non identical matrix) between consequitve runs. it will not guarntee that the matrix elements will be unique.

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

I could not understand

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

Observe that a matrix needs to be generated such that it a permutation of 1..100. Let us call is PI(1..100), if you generate a permutation of 1..100 and populate the matrix in any fashion you wish then you get a random matrix of 1..100.

To generate a random permutation of 1..100, the probability of generation of a particalr permutation say p should be = 1/ (100) !

that is pr { PI=p} = 1/100! for all p in PI(1..100)

``Pr{PI=p}= 1/100! = 1/100 * 1/99 * 1/98 .......* 1/2 * 1``

therefore you should be able to generate the first element with probability 1/100
second with 1/99 and so on and that would make p a random permutation.

To do this job initialize an array A={1,2,.......100}
generate an index between 0 to 99 using random function of ur choice
and choose A[index] now do a compaction of the array form index+1 to 99
so that the array has all elements in 1..100 except A[index] and array
elements occupy positions 0...98

repeat the above proc again this time generating random numebr between 0 to 98.

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

That's a magic square.

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

static int matrix[25] = { 1, 2, ... 25 };

void draw(int * pRandom1, int * pRandom2)
{
*pRandom1 = rand();
*pRandom2 = rand();
//NOTE, make sure the random1 and random2 are not identical.
}

void GenMatrix(const int MaxDrawTimes)
{
int r1, r2;

for (int i =0 ; i < MaxDrawTimes; ++i)
{
//Exchange eletements according to random draw
draw(&r1, &r2);
matrix[r1] <===> matrix[r2];
}
}

int main(int argc, char* argv[])
{
GenMatrix(rand());
//Print out generated matrix.
return 0;
}

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

Seems this is to let you generate matrix with a random algorithm in a very simple way.
Above idea is to use a fixed initialization layout and do several random rounds of item exchanges in a high performance.

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

I think the question was about the Magic Square too. Here is the perfect example.
ideone.com/wD2EpN

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.

### 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.