Adobe Interview Question for Computer Scientists

Country: United States

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

Answer = No of ways of placing the pair of queens on the board (Y) - No of ways in which the pair intersects (X)

Y = N*N *(N*N -1)

``````class Main
{
public static void main (String[] args) throws java.lang.Exception
{
int n = 8;
int arr[][] = new int[n][n];
long x = 0;
for (int i=0;i<n;i++){
for (int  j=0;j<n;j++){

x +=  Math.min(n-1-i, n-1-j) + Math.min(i, j) + Math.min(n-1-i,j) + Math.min(i,n-1-j);

x+= 2*n -2;
}
}

long ans = n*n * (n*n-1)  - x;
System.out.println(ans);
}
}``````

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

We can do this by combinations.
Observe that we have 64 * 63 possibilities for two queens, and we can change the order.
That is : 2 * 64 * 63 ways one can arrange 2 queens : T
Now, out of them, how many won't be stable?
Observe that a configuration is unstable iff The queens are in the same :
1. vertical
2. horizontal
3. diagonal.

1. Is possible by : 8 * P(8,2) ways : H
2. Is possible by : 8 * P(8,2) ways : V
3. Is possible by : 4 * ( P(8,2) + P(7,2) + ... P(2,2) ) : D

number of ways = T - H - V - D

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

Answer = No of ways of placing the pair of queens on the board (Y) - No of ways in which the pair intersects (X)

Y = N*N *(N*N -1)

``````class Main
{
public static void main (String[] args) throws java.lang.Exception
{
int n = 8;
int arr[][] = new int[n][n];
long x = 0;
for (int i=0;i<n;i++){
for (int  j=0;j<n;j++){

x +=  Math.min(n-1-i, n-1-j) + Math.min(i, j) + Math.min(n-1-i,j) + Math.min(i,n-1-j);

x+= 2*n -2;
}
}

long ans = n*n * (n*n-1)  - x;
System.out.println(ans);
}``````

}

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

``````class Main
{
public static void main (String[] args) throws java.lang.Exception
{
int n = 8;
int arr[][] = new int[n][n];
long x = 0;
for (int i=0;i<n;i++){
for (int  j=0;j<n;j++){

x +=  Math.min(n-1-i, n-1-j) + Math.min(i, j) + Math.min(n-1-i,j) + Math.min(i,n-1-j);

x+= 2*n -2;
}
}

long ans = n*n * (n*n-1)  - x;
System.out.println(ans);
}``````

}

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

``````class Main
{
public static void main (String[] args) throws java.lang.Exception
{
int n = 8;
int arr[][] = new int[n][n];
long x = 0;
for (int i=0;i<n;i++){
for (int  j=0;j<n;j++){

x +=  Math.min(n-1-i, n-1-j) + Math.min(i, j) + Math.min(n-1-i,j) + Math.min(i,n-1-j);

x+= 2*n -2;
}
}

long ans = n*n * (n*n-1)  - x;
System.out.println(ans);
}``````

}

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

``````class Main
{
public static void main (String[] args) throws java.lang.Exception
{
int n = 8;
int arr[][] = new int[n][n];
long x = 0;
for (int i=0;i<n;i++){
for (int  j=0;j<n;j++){

x +=  Math.min(n-1-i, n-1-j) + Math.min(i, j) + Math.min(n-1-i,j) + Math.min(i,n-1-j);

x+= 2*n -2;
}
}

long ans = n*n * (n*n-1)  - x;
System.out.println(ans);
}
}``````

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

1

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

1

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

1)

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

1"'`--

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

1

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

``````class Main
{
public static void main (String[] args) throws java.lang.Exception
{
int n = 8;
int arr[][] = new int[n][n];
long x = 0;
for (int i=0;i<n;i++){
for (int  j=0;j<n;j++){

x +=  Math.min(n-1-i, n-1-j) + Math.min(i, j) + Math.min(n-1-i,j) + Math.min(i,n-1-j);

x+= 2*n -2;
}
}

long ans = n*n * (n*n-1)  - x;
System.out.println(ans);
}``````

}

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

Answer = No of ways of placing the pair of queens on the board (Y) - No of ways in which the pair intersects (X)

Y = N*N *(N*N -1)

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

2576

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

if queens are exactly same each other, (64*63)/2. But if queens are different from each other, 64*63

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

Ans

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.