招聘是为了实习。第一轮是对 HackerEarth 的编码测试。有两个问题。两人各拿100分。
1.Min-Max 加权边
给定具有 N 个节点和 N-1 个双向边的树,并给定一个整数 S。现在,您必须将权重分配给这棵树的边,使得:
1.所有边的权重之和等于S。
2. 对于树的每个可能直径,其路径所覆盖的所有边上的最大权重是可能的最小值。
您必须输出可能的最小边缘权重。
注意:树的直径是树中两片叶子之间最长路径上的节点数。
Input Format:
The first line of the input contains an integer T the total number of test cases.
The first line of each test case contains two space-separated integers N and S, the number of nodes in a tree and the integer S as mentioned in the problem statement.
Then the N – L lines follow, each containing two space separated integers and u representing that there is a bidirectional edge between the nodes u and v.
Output Format:
For each test case output the minimum possible edge weight which satisfies the above-mentioned conditions.
Constraints
1 <= T <= 10
1 <= N <= 2 x 10^3
1 <= u, v <= N
1 <= S <= 10^9
Examples:
Input :
2
8 18
1 2
1 3
2 4
2 5
2 6
3 7
3 8
7 15
1 2
1 3
1 4
2 5
2 6
3 7
Output :
3
0
Explanation
Sample test case 1: Given below is one of the best ways to assign weights to the edges
Sample test case 2: Note that there are only two possible diameters of the tree: 5 to 7 and 6 to 7, so we can assign S to the edge {1, 4} and for every possible diameter of the tree, the maximum weight over all the edges covered by its path is 0.
2. 多彩建筑
一排有N栋楼。这些建筑物中的每一个都需要涂上 K 种颜色中的一种。只有当相邻的建筑物没有涂上相同的颜色时,建筑物才会看起来很漂亮。找出粉刷这些建筑物以使其美观的多种方法。由于该数字可能是非常大的输出,因此它以 10^9+7 为模。
Input Format
The first line of the input contains an integer T, the total number of test cases.
Then T lines follow, each containing two space-separated integers N and K, the total number of buildings and the number of colors available.
Output Format
For each test case output the number of ways to paint the buildings such that they are beautiful modulo 10^9+7.
Constraints
1 <= T <= 10
1 <= N <= 10^5
2 <= K <= 10^5
Sample Input
2
4 2
4 6
Sample Output
2
750
Explanation
Sample test case 1: Let A and B be the two available colors then there are just two possible ways of coloring the buildings as ABAB and BABA.
入围的候选人被要求在他们的班加罗尔办公室接受面试。第二轮也是编码轮。有两个问题。
1. 棋盘游戏
霍比特人曾要求甘德拉夫为他们准备一个棋盘游戏。所以甘德拉夫想出了这样的事情。会有像棋盘一样的 amxn 国际象棋,每个块都包含一个数字。一个人可以从任何数字开始,向右或向下移动,这样:
1、右边的数字不小于当前数字。
2. 下面的数字不大于当前数字。
鉴于这些限制,可以从任意数量开始的最大移动次数是多少。
Input Format
M – The number of rows
N – The number of columns
Followed by the numbers present on the board
Output Format
Maximum number of moves that can be made.
Sample Input 1:
3 3
1 9 1
2 3 1
3 4 1
Sample Output 1:
4
Sample Input 2:
2 2
2 1
3 2
Sample Output 2:
1
Sample Input 3:
2 2
4 5
3 6
Sample Output 3:
3
2.天网
天网已经成长为地球上的主导力量,几乎彻底消灭了人类。自成立以来,天网一直在制造机器人,并且每年都在更新其模型,同时使它们变得更好。天网想要彻底消灭人类。它计划移除由约翰康纳领导的最后一批人类。天网认为它可以只使用它的两个机器人就可以摧毁这些人类。但是天网不想发送两个型号相同的机器人,以免约翰康纳发现该型号的弱点并轻易摧毁它们。
天网有 N 个机器人可供使用,为了节省空间,天网存储了属于同一型号的机器人对的信息。如果它没有为特定机器人存储任何信息,则暗示该机器人是该模型中唯一的机器人。
鉴于这些限制,天网可以通过多少种方式挑选两个机器人来摧毁约翰康纳和他的破烂标签人类群体。
Input Format
N – Total number of robots. Each robot is assigned a number from 0 to N-1
P – Number of pairs for which Skynet has information
This is followed by P pairs. Each pair has two numbers P1 and P2 each where 0<=P1<=N-1 and 0<=P2<=N-1 and P1 != P2
Output Format
Number of ways in which Skynet can select 2 robots such that both the robots are different models.
Sample Input 1:
4 2
0 1
2 3
Sample Output 1:
4
Explanation: Here robots 0 and 1 are of one model, say model A. And 2 and 3 are of another model, say B. Therefore the total number of possibilities of picking 2 robots such that no two robots are of the same model are – (0, 2), (0, 3), (1, 2) and (1, 3) = 4
Sample Input 2:
10 4
2 8
1 3
0 2
5 8
Sample Output 2:
38
入围候选人进行了面对面的面试。面板上有两个人。讨论了两个问题的逻辑和实现。他们询问了它的时间复杂度以及优化它的方法。他们给出了另一个需要解决的问题。
将有一个二维数组,其中包含值 0 和 1。 0代表海洋,1代表陆地。输出存在的岛数。
Sample Input 1:
3 3
1 1 0
0 1 0
0 0 1
Sample Output 1:
2
Explanation:
The land is considered as one island if it is either stand alone or it can be reached from one land to other either vertically or horizontally but not diagonally. So the lands in first two rows are considered as one island and the one in the third row is considered as another one.
Sample Input 2:
3 3
0 1 1
0 1 0
1 1 0
Sample Output 2:
1
Sample Input 3:
3 3
0 1 0
0 0 1
1 0 1
Sample Output 3:
3
他们询问了我迄今为止最具挑战性的情况以及之前的实习经历。然后他们问我是否对公司有任何问题或反馈。