Cognzant Technology Solutions Interview Question for Android Engineers


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

- Luke Rhinehart August 16, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
2
of 2 vote

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

- Anonymous August 17, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

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

- Roman August 16, 2016 | Flag Reply
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);
    }

- Davide August 19, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

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

- eduandabhi August 16, 2016 | Flag Reply
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);
    }

- Davide August 19, 2016 | Flag Reply
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);
}

- Rohan Pandit August 22, 2016 | Flag Reply
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);
}

- Rohan Pandit August 22, 2016 | Flag Reply
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
}

- MyNameIsNobody August 28, 2016 | Flag Reply
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;

}

- Anonymous August 16, 2016 | Flag Reply
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;
}

- Anusri August 16, 2016 | Flag Reply
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;
}

- ricardolira48 August 16, 2016 | Flag Reply
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;
}

- Anaga August 16, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
2
of 2 votes

your solution is wrong.
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.

- settyblue August 16, 2016 | Flag
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;
}

- Anaga August 16, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
-2
of 2 vote

function F12(){

	return F6()+F6();
}

- Shahzad Mughal August 17, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
-2
of 2 vote

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

- Shahzad Mughal August 17, 2016 | 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