Codenation test was conducted on Hackerrank on 15th July. There were 3 questions in the hiring contest.↵
↵
Q1) Given a NxM (NxM <= 1e5) matrix with each cell having a value mod(Aij) <= 1e9. Job is to rank each element by the following rules:↵
↵
1) Ranks start from 1.↵
2) Equal elements in the same row or same column should have the same rank.↵
3) Greater elements in the same row or same column should have a greater rank.↵
4) Maximum Rank should be minimized.↵
↵
Print the final rank matrix.↵
↵
Q2) N employees are given, you have to divide them into teams of two. If n is odd the last person will form a one man team.↵
Problem is all employees are not compatible with each other. and if both are compatible with each other then only a teamcan ↵
can be formed.↵
↵
Aij ='C' if employee i is compatible with employee j, Aij = 'X' otherwise.↵
Aii ='C' if employee i can work as one man team, Aii = 'X' otherwise.↵
↵
find the maximum no of valid teams that can be formed.↵
constraints: T <=20, N<=18.↵
↵
Q3) Given a Directed graph with N nodes and M edges. each node has a population Ai.↵
you have to open outlets in some or all nodes following the conditions in decreasing priority:↵
↵
1) Every Node must have access to some outlet either directly or through some path.↵
2) Maximize the average sales per outlet. sales are linearly proportional to the no of people that visit that location. ↵
↵
location. Average sales per outlet = (sum of all outlet sales)/(total number of outlets)↵
3) Minimize the number of outlets.↵
↵
Print how many outlets will you open and in which node.↵
Constraints : T <= 100, N <= 1e3, M <= min( 1e5, N(N-1)), Ai <= 1e3.↵
↵
Please share your approach on how you solved each of them.
↵
Q1) Given a NxM (NxM <= 1e5) matrix with each cell having a value mod(Aij) <= 1e9. Job is to rank each element by the following rules:↵
↵
1) Ranks start from 1.↵
2) Equal elements in the same row or same column should have the same rank.↵
3) Greater elements in the same row or same column should have a greater rank.↵
4) Maximum Rank should be minimized.↵
↵
Print the final rank matrix.↵
↵
Q2) N employees are given, you have to divide them into teams of two. If n is odd the last person will form a one man team.↵
Problem is all employees are not compatible with each other. and if both are compatible with each other then only a team
can be formed.↵
↵
Aij ='C' if employee i is compatible with employee j, Aij = 'X' otherwise.↵
Aii ='C' if employee i can work as one man team, Aii = 'X' otherwise.↵
↵
find the maximum no of valid teams that can be formed.↵
constraints: T <=20, N<=18.↵
↵
Q3) Given a Directed graph with N nodes and M edges. each node has a population Ai.↵
you have to open outlets in some or all nodes following the conditions in decreasing priority:↵
↵
location. Average sales per outlet = (sum of all outlet sales)/(total number of outlets)↵
↵
Print how many outlets will you open and in which node.↵
Constraints : T <= 100, N <= 1e3, M <= min( 1e5, N(N-1)), Ai <= 1e3.↵
↵
Please share your approach on how you solved each of them.