This assessment contains three independent programming tasks. Solve each one separately; the inputs and state of one task do not affect another.
There are n competitors placed in a row and numbered from 1 to n. Competitor i has ability value a[i], and the values a[1..n] are a permutation of the integers 1 through n, so every ability appears exactly once.
The tournament is played in rounds. In each round, the current competitors are paired from left to right: first with second, third with fourth, and so on. Within each pair, the competitor with the larger ability wins and stays in the tournament; the other competitor is eliminated. The winners keep their relative left-to-right order and form the list of competitors for the next round. The process continues until only one competitor, the champion, remains.
Given n and the array a, return an array b[1..n], where b[i] is the total number of matches competitor i participates in before being eliminated or winning the tournament.
A robot moves on an R by C grid. Each cell is one of the following:
# — a wall; the robot may never enter it.. — an empty floor cell that can be entered.* — the robot's starting floor cell.The outermost border of the grid consists entirely of walls. All floor cells are guaranteed to form one connected region. The robot can move one cell up, down, left, or right using the commands ^, v, <, and >. After every command, the robot must still be inside the grid and on a floor cell. The robot does not need to return to its starting cell.
For each test case, one of the following five shape variants is specified. You must output one command string of length at most 100000. If multiple valid command strings exist, any is accepted. You may assume that a valid command string of length at most 100000 exists for the given grid and variant.
You are given an array a[1..n] of non-negative integers. For each number, consider its set of decimal digits when written in base 10 without leading zeros. For example, 12 contains digits {1, 2} and 340 contains digits {3, 4, 0}.
Two distinct indices i and j are compatible if i != j and the digit sets of a[i] and a[j] are disjoint. Return the maximum possible sum of two compatible values, a[i] + a[j]. If no compatible pair exists, return -1.
Example 1:
Input:
n = 8
a = [3, 7, 2, 8, 1, 5, 4, 6]
Output: [1, 2, 1, 3, 1, 2, 1, 3]
Explanation: Competitor 4 wins the tournament and plays 3 matches. Competitor 8 also plays 3 matches. Competitors 2 and 6 play 2 matches each, and competitors 1, 3, 5, and 7 play 1 match each.
n = 8 a = [3,7, 2, 8, 1, 5, 4, 6]
[1,2, 1, 3, 1, 2, 1, 3]
Competitors 1..8 with abilities a = [3, 7, 2, 8, 1, 5, 4, 6].
Example 2:
Input:
Subtask: 2
R = 5, C = 5
grid = [
"#####",
"#*..#",
"#...#",
"#...#",
"#####"
]
Output: ">>v<<v>>"
Explanation: The robot starts at the top-left cell of the interior 3 x 3 floor rectangle and visits all nine floor cells without entering any wall.
Example 3:
Input:
a = [23, 45, 16, 67, 0]
Output: 112
Explanation: The values 45 and 67 have digit sets {4, 5} and {6, 7}, which are disjoint. Their sum is 112, and no other compatible pair gives a larger sum.
Constraints:
n is a power of two.a[1..n] is a permutation of the integers 1 through n.^, v, <, > and have length at most 100000.-1.n = 8 a = [3,7, 2, 8, 1, 5, 4, 6]
[1,2, 1, 3, 1, 2, 1, 3]
Competitors 1..8 with abilities a = [3, 7, 2, 8, 1, 5, 4, 6].