Task 1
You are given an array A of N integers, representing the maximum heights of N skyscrapers to be built.
Your task is to specify the actual heights of the skyscrapers, given that:
- the height of the K-th skyscraper should be positive and not bigger than A[K];
- no two skyscrapers should be of the same height;
- the total sum of the skyscrapers' heights should be the maximum possible.
Write a function:
class Solution { public int[] solution(int[] A); }
that, given an array A of N integers, returns an array B of N integers where B[K] is the assigned height of the K-th skyscraper satisfying the above conditions.
If there are several possible answers, the function may return any of them. You may assume that it is always possible to build all skyscrapers while fulfilling all the requirements.
Examples:
- Given A = [1, 2, 3], your function should return [1, 2, 3], as all of the skyscrapers may be built to their maximum height.
- Given A = [9, 4, 3, 7, 7], your function may return [9, 4, 3, 7, 6]. Note that [9, 4, 3, 6, 7] is also a valid answer. It is not possible for the last two skyscrapers to have the same height. The height of one of them should be 7 and the other should be 6.
- Given A = [2, 5, 4, 5, 5], your function should return [1, 2, 3, 4, 5].
Write an efficient algorithm for the following assumptions:
- N is an integer within the range [1..50,000];
- each element of array A is an integer within the range [1..1,000,000,000];
- there is always a solution for the given input.

Task 2
There are two wooden sticks of lengths A and B respectively. Each of them can be cut into shorter sticks of integer lengths. Our goal is to construct the largest possible square. In order to do this, we want to cut the sticks in such a way as to achieve four sticks of the same length (note that there can be some leftover pieces). What is the longest side of square that we can achieve?
Write a function:
class Solution { public int solution(int A, int B); }
that, given two integers A, B, returns the side length of the largest square that we can obtain. If it is not possible to create any square, the function should return 0.
Examples:
- Given A = 10, B = 21, the function should return 7. We can split the second stick into three sticks of length 7 and shorten the first stick by 3.
- Given A = 13, B = 11, the function should return 5. We can cut two sticks of length 5 from each of the given sticks.
- Given A = 2, B = 1, the function should return 0. It is not possible to make any square from the given sticks.
- Given A = 1, B = 8, the function should return 2. We can cut stick B into four parts.
Write an efficient algorithm for the following assumptions:
- A and B are integers within the range [1..1,000,000,000].

Task 3
You are given a rooted tree. For example, the figure below shows a tree made of six nodes.

A node is balanced if all of its subtrees are of the same size. The size of the subtree is the number of nodes it contains.
The tree above has five balanced nodes marked in gray. The root is not balanced because its subtrees are of different sizes: the left subtree’s size equals 3 and the right subtree’s size equals 2.
Write a function:
class Solution { public int solution(Node tree); }
that, given a tree, returns the number of balanced nodes it contains.
Technical details:
Assume that the following declarations are given:
class Node {
public Node[] subtrees;
}
A tree is specified using a pointer data structure. For each Node, the attribute subtrees holds pointers to its subtrees.
Examples:
- For the above tree, the function should return 5.
- For the following tree, the function should return 6. Balanced nodes are marked in gray

3.For the following tree, the function should return 7.

Assume that:
- number of nodes is an integer within the range [1..100].
In your solution, focus on correctness. The performance of your solution will not be the focus of the assessment.

我们长期稳定承接各大科技公司如Epic、Uber、Amazon等的OA笔试代写服务,确保满分通过。如有需求,请随时联系我们。
We consistently provide professional online assessment services for major tech companies like TikTok, Google, and Amazon, guaranteeing perfect scores. Feel free to contact us if you're interested.

