Microsoft Interview Question
Software Engineer / DevelopersOne thing that we have to see if that middle number is 2 and 3 are adjacent to 6 number. So if we take numbers from 1 to 8 then only 1 and 8 satisfy the condition that there are 6 number in the series that are not adjacent to them......Placing other number is just a matter of time.......
Hi,
In my opinion, number of possible seating arrangements has more value addition to the conversation than providing a sample case.
I see 12 as one of the answer. Can some help us understand about the manipulations behind it.
By doing mathematics,
Total possible seating arrangements = 8!
Total coupling in the arrangement = 15
8! = n(X=0) + n(X=1) + n(X=2).......n(X=15)
I think for X>5 , n(X) =0;
I am thinking , Can anyone join the pieces?
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll cnt = 0;
int row, column;
void solve(int arr[11][11], int n, int i_previous, int j_previous){
if(n == row*column+1 || n == row*column-3){
for(int i = 1; i <= row; ++i){
for(int j = 1; j <= column; ++j)
cout << arr[i][j] << ' ';
cout << '\n';
}
cout << '\n';
++cnt;
return;
}
for(int i = 1; i <= row; ++i){
for(int j = 1; j <= column; ++j){
if((abs(j-j_previous) >= 2 || abs(i-i_previous) >= 2) && arr[i][j] == 0){
arr[i][j] = n;
//cout << "(i) : " << i << ' ' << "(j) : " << j << ' ' << arr[i][j] << endl;
solve(arr, n+1, i, j);
arr[i][j] = 0;
}
}
}
return;
}
int main(){
cout << "Please Enter \"Row\" and \"Column\"" << endl;
cout << "Row : "; cin >> row;
cout << "Column : "; cin >> column;
int arr[11][11] = {};
arr[1][2] = -1, arr[1][3] = -1, arr[4][2] = -1, arr[4][2] = -1, arr[4][3] = -1;
solve(arr, 1, -2,-2);
cout << cnt;
return 0;
Code in c++
2
- pusi August 23, 2009586
314
7