## Cognzant Technology Solutions Interview Question for Android Engineers

• 1
of 1 vote

Country: India
Interview Type: Written Test

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

``````from random import randint

def F6():
return randint(1,6)

def F12() :
j = F6()
if j%2 == 0 :
return F6()
else :
return 6+F6()``````

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

``````public static int F12(){
return F6() + (F6()%2)*6
}``````

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

``````public static int F12(){
return F6()*2 - (F6()&1);
}``````

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

``````private int F6() {
Random random = new Random();
return random.nextInt(5) + 1;
}

private int F12() {
Random random = new Random();
int j = random.nextInt(1);
return F6() + (6 * j);
}``````

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

Is there someone who can write the full code in java?

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

``````private int F6() {
Random random = new Random();
return random.nextInt(5) + 1;
}

private int F12() {
Random random = new Random();
int j = random.nextInt(1);
return F6() + (6 * j);
}``````

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

``````public static int F6(int[] arr, int turn) {
if(turn == arr.length)
return arr[arr.length - turn];
Random random = new Random();
int number = random.nextInt(arr.length - turn);
int probNumber = arr[number];
int temp = arr[number];
arr[number] = arr[arr.length - turn];
arr[arr.length - turn] = temp;
return probNumber;
}

public static void F12(int[] arr){
boolean[] flag = new boolean[6];
for(int i=0; i< 12; i++){
int number = F6(arr,(i % 6) + 1);
if(!flag[number-1]){
flag[number-1] = true;
System.err.println(number);
}
else
System.err.println(number + 6);
}
}

static void main(String[] args){
int[] arr = new int[]{1,2,3,4,5,6};
for(int i=0; i< arr.length; i++){
System.err.println(F6(arr,i+1));
}

F12(arr);
}``````

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

public static int F6(int[] arr, int turn) {
if(turn == arr.length)
return arr[arr.length - turn];
Random random = new Random();
int number = random.nextInt(arr.length - turn);
int probNumber = arr[number];
int temp = arr[number];
arr[number] = arr[arr.length - turn];
arr[arr.length - turn] = temp;
return probNumber;
}

public static void F12(int[] arr){
boolean[] flag = new boolean[6];
for(int i=0; i< 12; i++){
int number = F6(arr,(i % 6) + 1);
if(!flag[number-1]){
flag[number-1] = true;
System.err.println(number);
}
else
System.err.println(number + 6);
}
}

static void main(String[] args){
int[] arr = new int[]{1,2,3,4,5,6};
for(int i=0; i< arr.length; i++){
System.err.println(F6(arr,i+1));
}

F12(arr);
}

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

``````/* Observe the  law of independence P(AB) = P(A) * P(B).
So, the best way is to partition the product space :
Let A = { 1, 2, 3, 4, 5, 6 }
A* A can be generated by simply doing F2(), F(2)
That gives 6 * 6 := 36 permutations. But we need to generate 1...12.
Thus, we splice by 3.
[ 11 | 12 | 13 ] --> 1
[ 14 | 15 | 16 ] --> 2
.... you got the idea
*/
// hence....

map = { '11' : 1 , '12' : 1, '13: 1 ,
'14 : 2,  '15' : 2 , '16' : 2 ,
.... }

def  F12(){
x = F6()
y = F6()
key = str(x) + str(y)
return map[key] // and we are done
}``````

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

``````int F12(){

boolean flag[6];
int num=F6();
if(flag[num]==false){
flag[num]=true;

}
else{
num=num*2;
flag[num]=false;
}
return num;``````

}

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

``````int F12(){

boolean flag[6];
int num=F6();
if(flag[num]==false){
flag[num]=true;

}
else{
num=num*2;
flag[num]=false;
}
return num;
}``````

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

public static int F12(){
int num = F6();
if(F6() > 3){
return num*2;
}
return num;
}

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

int F12(){

boolean flag[6];
int num=F6();
if(flag[num]==false){
flag[num]=true;

}
else{
num=num*2;
flag[num]=false;
}
return num;
}

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

Consider the following simple case.
What is the probability of getting 2 or 4?
it is not 1/12. it is 2/12.
What is the probability of getting 7, 9 or 11? it is 0.
There are many other mistakes, these are the simple ones that I can point out.

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

int F12(){

boolean flag[6];
int num=F6();
if(flag[num]==false){
flag[num]=true;

}
else{
num=num*2;
flag[num]=false;
}
return num;
}

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

``````function F12(){

return F6()+F6();
}``````

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

``````function F12(){
return F6()+F6();
}``````

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.