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

- Parikh November 27, 2016 | Flag Reply
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

- NoOne December 02, 2016 | Flag Reply
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);
	}

}

- Parikh November 27, 2016 | Flag Reply
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);
	}

}

- Parikh November 27, 2016 | Flag Reply
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);
	}

}

- Anonymous November 27, 2016 | Flag Reply
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);
	}
}

- Anonymous November 27, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

1

- arachni_name) November 14, 2018 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

1

- arachni_name"'`-- November 14, 2018 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

1)

- arachni_name November 14, 2018 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

1"'`--

- arachni_name November 14, 2018 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

1

- arachni_name November 14, 2018 | Flag
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);
	}

}

- Parikh November 27, 2016 | Flag Reply
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)

- Parikh November 27, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

2576

- m@}{ November 27, 2016 | Flag Reply
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

- passanger November 27, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

Ans

- Anonymous November 27, 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