vinod
BAN USER- 0of 2 votes
AnswersIn the Amazon Office, Employees are use to sit in cubical offices and all the offices are connected with some other offices, but they are not arranged in any well defined order. Offices are connected means they are sharing their walls with other offices. There are two types of Employees in Amazon i.e. 'Testers' and 'Developers'. Manager of Amazon don't want any 'Tester' and 'Developer' to sit in nearby cubical office, it means there should not be any shared wall between two 'Testers'/'Developers'.
- vinod in India
Input:- First line consist of an integer n, which is number of common walls.
Next n lines consist of 2 integers a and b, which represents the Office Number between which the wall is being shared.
Output: - Print 'Yes', if condition of the manager can be satisfied and print 'No' if not.
Example: -
1-2-3
|
4
Office number 2 is sharing its 3 walls with Office 1,3 & 4.....that is why if Office 2 has a 'Developer' than Office 1,3 & 4 cannot have any 'Developer'.
INPUT:-
3
1 2
2 3
2 4
Output: -
Yes
Any better approach then DFS i.e. O(V+E)..??| Report Duplicate | Flag | PURGE
Amazon Intern Trees and Graphs - 2of 4 votes
AnswersSearch in a row wise and column wise sorted matrix
- vinod in India| Report Duplicate | Flag | PURGE
Amazon Intern Matrix - 0of 0 votes
AnswersReplace each node with the sum of all greater nodes in a given BST?
- vinod in India| Report Duplicate | Flag | PURGE
Amazon Intern Trees and Graphs - 1of 1 vote
AnswersHow will you Serialize and Deserialize the binary tree?
- vinod in India| Report Duplicate | Flag | PURGE
Amazon Intern Algorithm
//There are 4 answers for the above question
#include<stdio.h>
#include<string.h>
int dfs(char **mat, int R,int C, char *search,int r,int c, int index)
{
//printf("%d %d %d\n",r,c,index);
int answer=0;
if(index==strlen(search)-1)
return 1;
if(r>=R || c>=C)
return 0;
if(mat[r+1][c]==search[index+1])
answer+=dfs(mat,R,C,search,r+1,c,index+1);
if(mat[r][c+1]==search[index+1])
answer+=dfs(mat,R,C,search,r,c+1,index+1);
if(mat[r+1][c+1]==search[index+1])
answer+=dfs(mat,R,C,search,r+1,c+1,index+1);
return answer;
}
int find_1stLetter(char **mat,int R,int C,char *search)
{
int i,j, answer=0;
for(i=0;i<R;i++)
{
for(j=0;j<C;j++)
{
if(mat[i][j]==search[0])
{
//printf("%c %c--",mat[0][0],search[0]);
//printf(".%d %d.\n",i,j);
answer+=dfs(mat,R,C,search,i,j,0);
}
}
}
return answer;
}
int main()
{
int i,j;
char *mat[]={"wsrtgg","aachin","kchujj","ohinyq"};
char search[15]={'s','a','c','h','i','n','\0'};
int answer=find_1stLetter(mat,4,6,search);
printf("\nanswer=%d\n",answer);
return 0;
}
its not required... :)
- vinod January 24, 2014