Huawei | 2022 General Software Engineer Internship | Online Assessment

A total of 3 questions in 2h, worth 100, 200, 300 points, respectively. Need to write code to handle input and output (in Python, use sys.stdin) and write test cases.

  1. Given a binary tree and any node v that's not the root node, we can divide the tree into two subtrees: the first subtree has root v, and the second subtree is whatever is left after removing the first subtree from the original tree. Find the node v s.t. the absolute value of the difference between the sum of values of the two subtrees is the largest.
  2. Given a M*N matrix, each cell contains a value 0, 1, 2, .... A positive value represents the maximum steps you can make from this cell, while a value of 0 means that you cannot arrive at this cell. You can only move downwards or to the right. Given that you start from (0, 0), what's the minimum number of cells you'll visit in order to reach (M-1, N-1), including this final cell? If you cannot reach it, return -1.
  3. You are given a target module and a list of information about modules. In each line, you are given the name of the module, the compile time of the module, and the names of the module's dependencies, if there are any. (e.g. module3, 5, module1, module2 would be a line of input representing module3 needs module1 and module2 in order to compile). Return the minimum time needed to compile the target module. If the target can't be compiled, return -1.
Comments (0)