Qualcomm Interview Question for Software Engineer in Tests


Country: United States
Interview Type: In-Person




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

public static void set_random_no_repeated(int[][] test,int maxValue){
if(maxValue<test.length*test[0].length){
System.out.println("No way!");
return;
}
HashMap<Integer,Boolean> map=new HashMap<Integer,Boolean>();
for(int i=0;i!=test.length;i++){
for(int j=0;j!=test[0].length;j++){
int setValue=0;
do{
setValue=(int)(Math.random()*maxValue);
}
while(map.containsKey(setValue));
map.put(setValue, true);
test[i][j]=setValue;
}
}
}

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

* Program to fill in values for a 10 X 10 array.
The function should fill the array with random,
non-repeated values every time the function is called

input -> 100 numbers using 2x2 matrix.

output -> 84 87 78 16 94 36 100 93 50 22 63 28 91 60 64 27 41 100 73 37
12 69 68 30 83 31 100 24 100 100 100 3 23 59 70 100 100 57 100
43 100 74 100 20 85 38 99 25 100 71 14 100 92 81 100 100 100 100
97 82 6 26 100 100 100 100 47 100 100 58 100 96 100 46 15 100 35
65 44 51 88 9 77 79 89 100 4 52 55 100 33 61 100 100 40 13 100 100 95 100
*/

#include<stdio.h>
static int size;
int rval;
int pool[100];
int generaterRandom(int s);

int main()
{
int i,j;
int arr[10][10];
for(i = 0; i < 100 ; i++)
{
pool[i] = i+1;
}
for(i = 0; i < 10 ; i++)
{
for(j = 0; j < 10 ; j++)
arr[i][j] = generaterRandom(100);
}
for(i = 0; i < 10 ; i++)
{
for(j = 0; j < 10 ; j++)
printf("%d ", arr[i][j]);
}
}

int generaterRandom(size)
{
if (size < 1)
return -1;
int idx = rand()%size;
size--;
rval = pool[idx];
pool[idx] = pool[size];
return rval;
}

- Arun September 05, 2012 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

int pool[100];
int main()
{


int generaterRandom(int s);
int arr[10][10];
//int n = ;
//cout<<n;
 for(int i = 0; i < 100 ; i++)
{
       pool[i] = i+1;
}

 for(int i = 0; i < 10 ; i++)
 {
    for(int j = 0; j < 10 ; j++)
        arr[i][j] = generaterRandom(100);
}



 for(int i = 0; i < 10 ; i++)
 {
    for(int j = 0; j < 10 ; j++)
        cout << arr[i][j]<<", ";
    cout<<endl;
}

}


int generaterRandom(int s)
{
static int size = s;
if (size < 1) 
    return -1;
int idx = rand()%size;
    size--;
        int rval = pool[idx];
        pool[idx] = pool[size];
        return rval;

}

- Anonymous April 09, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

10 x 10 array of ints??

- King@Work February 26, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Use of hash map and a random function can do this

- Alas February 27, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

no using random function alone is not enough at least you have to make sure that the seed every time is diffrent , you can achive that by using the time function or other tech. but the time function is the easier way !

- Ammar April 08, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Use of hash map and a random function can do this

- Alas February 27, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Can design a maximal shift register to generate random numbers newly every time

- Anonymous May 29, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int main()
{
// Populate 10x10 array with random numbers
int a[10][10];
srand(time(NULL));
for(int i = 0; i < 10; i++)
{
for(int j = 0; j < 10; j++)
{
a[i][j] = rand()%1000;
printf("%d ", a[i][j]);
}
printf("\n");
}

return 0;
}

- Candida June 21, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

srand(time(NULL));

should be used here .

- pkp June 28, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.*;
public class RandomMatrix
{
	public static void main (String [] args)
	{
		Random rn = new Random();
		int no = 0;
		//int no = rn.nextInt(100);
		//System.out.println(no);
		//Scanner sc = new Scanner(System.in);
		int array [] []  = new int[10][10];
		int array1 []  = new int[1000];
		for(int i = 0 ; i<10 ; i++)
		{
			for(int j = 0 ; j< 10 ; j++)
			{
				 no = rn.nextInt(1000);
				System.out.println(no);
				if(array1[no] ==  no)
				{
					System.out.println("inside");
					continue;			
				}
				else
				{
					array[i][j] = no;
					no = 0;	
				
				}
			}
		}
		for(int i = 0 ; i<10 ; i++)
		{
			for(int j = 0 ; j< 10 ; j++)
			{
				System.out.print(array[i][j]);
				System.out.print("\t");
			}
		System.out.print("\n");
		}
		
	}

}

- Arun Kumar Gupta July 20, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

no time function is needed .... thanx

- Arun Kumar Gupta July 20, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

This problem can be solved by standard technique of selecting a random permutation of k numbers from n given unique numbers.
Every time our required function is called do the following
1. select a random range of n numbers (unique)
2. here k=10*10
3. n >> k (preferably)
4. copy 1st k numbers to matrix (assume the matrix is an array of 100 elements now)
5. at each step generate a random number between 1 to i, where i varies from k+1 to n.
6. if generated value is between 1 to k, then replace val[k] by val[i]. Else continue
7. Convert array into matrix and display
5.

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

for (i = 0; i < 100; i++) {
		list[i] = i;
	}

	for (i = 0; i < 100; i++) {
		int j = i + rand() % (100 - i);
		int temp = list[i];
		list[i] = list[j];
		list[j] = temp;
	}

	for (i = 0; i < 100; i++) {
		a[i/10][i%10] = list[i];
	}

- Rohit Khanna June 21, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Shuffling algo.

- Rohit Khanna June 21, 2013 | Flag


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