## Deshaw Inc Interview Question for Development Support Engineers

• 1
of 1 vote

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

I am not sure if I understand this question. Can you provide a couple of example squares?

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

when N=3
a1 a2 a3
b1 b2 b3
c1 c2 c3
a1+b2+c3+a3+b2+c1=a1+a2+a3+b1+b2+b3+c1+c2+c3
so b2=a2+b1+b3+c2
you can have infinite solutions to satisfy above equation.
like
0 1 0 2 0 2
1 4 1 1 2 1
0 1 0 2 0 2 ......
if I understand correctly

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

I think the elements in the magic squares should be 1, 2, 3, ... N*N. For instance, the following is a magic square:
8 1 6
3 5 7
4 9 2,
as the sum of elements in each row or column or diagonals is 15.

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

hi pramodh ,
did you undergo d interview process for a developer's role ??
if yes then please let me know the format.

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

Here is the code:

/**
* Creates a Magic Square of dimension num*num where num is any odd number.
* The procedure for creating a magic square of odd dimension is given here,
* http://en.wikipedia.org/wiki/Magic_square
* I just tried to wrote it in Java.
* @param num Integer specifying the dimension of the Magic Square
* @return Two dimensional int array, which is a perfect Magic Square.
*/
public int[][] createMagicSquare(int num){
int[][] magicSquare = new int[num][num];

// Initialize MagicSquare to 0
for(int i = 0; i < num; i++)
for(int j = 0; j < num; j++)
magicSquare[i][j] = 0;

int row = 0;
int col = num / 2;
int count = 1;

for(int i = 0; i < num; i++){
for(int j = 1; j <= num; j++){
if(magicSquare[row][col] == 0 )
magicSquare[row][col] = count;
else{
row = row + 2;
col = col -1;

if(row >= num)
row -= num;
if(col < 0)
col += num;
magicSquare[row][col] = count;
}

row = row - 1;
if(row == -1)
row = num + row;

col = col + 1;
if( col == num)
col = 0;

count++;
}
}
return magicSquare;
}

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

square[][]-->initialized to 0

square[0][n/2]=1;
row=0;
col=n/2;
for(i=2;i<=n*n;i++)
{
if(row>=1)
r=row-1;
else
r=n-1;

if(col>=1)
c=col-1;
else
c=n-1;

if(square[r][c]>=1)
row=(row+1)%n;
else
{
row=r;
col=c;
}
square[row][col]=i;
}

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

if(row>=1)
r=row-1;
else
r=n-1;

Can u pls tell me the use of these lines

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

row thing is right .
but i think in place of vol there should be c = col +1

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

if(col>=1)
c=col-1;
else
c=n-1;

that part should be
like
if(col < n-1)
c = col+1;
else
c = col - n +1 ;

assuming array scripting starts from 0 not 1 i.e sq[0][0] is starting element and not sq[1][1]

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

The technique used for generating a magic square is called the Siamese method.
Below is its implementation in C for a matrix of size 3X3.

``````/*
Magic square
*/

#include<stdio.h>
#include<math.h>

#define N 9
int magic(int a[][3],int i,int j,int count)
{
int k , l;
a[i][j] = count;
while(count<N)
{
++count;
/*Go up and then right*/
k = 3- i - ((i+1)%3);
l=(j+1)%3;

if(!a[k][l])
{

a[k][l] = count;
i = k;j = l;
}
else
{	/*If up and right is taken, then just go to the cell below*/
i = (i+1)%3;
a[i][j] = count;

}

}
}

int main()
{

int a[3][3]={0};
int i,j,n = 3;
magic(a,0,1,1);

for(i=0;i<n;i++)
{
printf("\n");
for(j=0;j<n;j++)
printf("%d\t",a[i][j]);
}

}``````

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

I think the question is about Ramanujan's Number

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

``All Possible!!``

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

A[i][j] = n((i+j-1)mod n) + (i+2j-2)mod n + 1
where (i,j) => (1,1) to (n,n)

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

How can we generate all possible matrix using this code ?
Like 3*3 have 8 possible matrix how those can be generated ?

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

import java.util.*;
class magic
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter dimension of matrix :-");
int n=sc.nextInt();
int A[][]=new int[n][n];
int r=n-1,c=n/2;
A[r][c]=1;
for(int i=2;i<=n*n;i++)
{
if(A[(r+1)%n][(c+1)%n]==0)
{
r=(r+1)%n;
c=(c+1)%n;
}
else
r=(r-1+n)%n;

A[r][c]=i;
}
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
System.out.print(A[i][j]+"\t");
}
System.out.print("| \t");
for(int j=0;j<n;j++)
{
System.out.print(A[j][i]+"\t");
}
System.out.println();
}
System.out.println();
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
System.out.print(A[n-1-i][n-1-j]+"\t");
}
System.out.print("| \t");
for(int j=0;j<n;j++)
{
System.out.print(A[n-1-j][n-1-i]+"\t");
}
System.out.println();
}
System.out.println();
for (int i=0;i<n;i++ ) {
for(int j=0;j<n;j++)
{
System.out.print(A[n-1-j][i]+"\t");
}
System.out.print("| \t");
for(int j=0;j<n;j++)
{
System.out.print(A[n-1-i][j]+"\t");
}
System.out.println();
}
System.out.println();
for (int i=0;i<n;i++ ) {
for(int j=0;j<n;j++)
{
System.out.print(A[i][n-1-j]+"\t");
}
System.out.print("| \t");
for(int j=0;j<n;j++)
{
System.out.print(A[j][n-1-i]+"\t");
}
System.out.println();
}

}
}

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

import java.util.*;
class magic
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter dimension of matrix :-");
int n=sc.nextInt();
int A[][]=new int[n][n];
int r=n-1,c=n/2;
A[r][c]=1;
for(int i=2;i<=n*n;i++)
{
if(A[(r+1)%n][(c+1)%n]==0)
{
r=(r+1)%n;
c=(c+1)%n;
}
else
r=(r-1+n)%n;

A[r][c]=i;
}
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
System.out.print(A[i][j]+"\t");
}
System.out.print("| \t");
for(int j=0;j<n;j++)
{
System.out.print(A[j][i]+"\t");
}
System.out.println();
}
System.out.println();
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
System.out.print(A[n-1-i][n-1-j]+"\t");
}
System.out.print("| \t");
for(int j=0;j<n;j++)
{
System.out.print(A[n-1-j][n-1-i]+"\t");
}
System.out.println();
}
System.out.println();
for (int i=0;i<n;i++ ) {
for(int j=0;j<n;j++)
{
System.out.print(A[n-1-j][i]+"\t");
}
System.out.print("| \t");
for(int j=0;j<n;j++)
{
System.out.print(A[n-1-i][j]+"\t");
}
System.out.println();
}
System.out.println();
for (int i=0;i<n;i++ ) {
for(int j=0;j<n;j++)
{
System.out.print(A[i][n-1-j]+"\t");
}
System.out.print("| \t");
for(int j=0;j<n;j++)
{
System.out.print(A[j][n-1-i]+"\t");
}
System.out.println();
}

}
}

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

this will generate all 8 possible magic square and for any value of n

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

``````import java.util.*;
class magic
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter dimension of matrix :-");
int n=sc.nextInt();
int A[][]=new int[n][n];
int r=n-1,c=n/2;
A[r][c]=1;
for(int i=2;i<=n*n;i++)
{
if(A[(r+1)%n][(c+1)%n]==0)
{
r=(r+1)%n;
c=(c+1)%n;
}
else
r=(r-1+n)%n;

A[r][c]=i;
}
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
System.out.print(A[i][j]+"\t");
}
System.out.print("| \t");
for(int j=0;j<n;j++)
{
System.out.print(A[j][i]+"\t");
}
System.out.println();
}
System.out.println();
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
System.out.print(A[n-1-i][n-1-j]+"\t");
}
System.out.print("| \t");
for(int j=0;j<n;j++)
{
System.out.print(A[n-1-j][n-1-i]+"\t");
}
System.out.println();
}
System.out.println();
for (int i=0;i<n;i++ ) {
for(int j=0;j<n;j++)
{
System.out.print(A[n-1-j][i]+"\t");
}
System.out.print("| \t");
for(int j=0;j<n;j++)
{
System.out.print(A[n-1-i][j]+"\t");
}
System.out.println();
}
System.out.println();
for (int i=0;i<n;i++ ) {
for(int j=0;j<n;j++)
{
System.out.print(A[i][n-1-j]+"\t");
}
System.out.print("| \t");
for(int j=0;j<n;j++)
{
System.out.print(A[j][n-1-i]+"\t");
}
System.out.println();
}

}
}``````

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.