## Cognzant Technology Solutions Interview Question

Android Engineers**Country:**India

**Interview Type:**Written Test

```
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);
}
```

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);

}

```
/* 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
}
```

int F12(){

boolean flag[6];

int num=F6();

if(flag[num]==false){

flag[num]=true;

}

else{

num=num*2;

flag[num]=false;

}

return num;

}

- Luke Rhinehart August 16, 2016