1. Area of Triangle (Easy)
Given three sets of distinct coordinates that form a triangle, calculate the area of the triangle. At least one side of the triangle will be parallel to either the x-axis or the y-axis.
Example
x = [0, 3, 0]
y = [0, 3, 2]
Aligned by index, the 3 coordinates are (0,0), (3,3), (0,2). The base of the triangle is 2, and the height is 3. The area of a triangle is (base * height) / 2, so 3 * 2 / 2 = 3. All resulting areas will be whole numbers.

Function Description
Complete the function getTriangleArea in the editor below.
Function Parameters:
def getTriangleArea(x: List[int], y: List[int]) -> int:
- x[3]: An integer array that denotes the x-coordinates.
- y[3]: An integer array that denotes the y-coordinates, aligned by x index.
Returns:
- long int: The area of the triangle.
2. Identical Distribution
An e-commerce company specializes in cards with sports figures on them. Each sport has different categories of cards. For instance, there might be more desirable cards with the most popular sports personalities, others with small pieces of a player's jersey attached, and so on. They have a number of each category of card and want to make some number of packets greater than 1 that all contain equal numbers of each type of card. To do this, they will add more cards of each type until each type can be divided equally among some number of packets. Determine the minimum number of additional cards needed to create a number of packets with equal type distribution.
Example
n = 5
cardTypes = [2, 8, 7, 11, 15]
In order to make 2 matching packets, the following numbers of additional cards of each type must be added: (0, 1, 1, 1, 1). This sums to 4 additional cards. The numbers of cards are [4, 8, 7, 16, 18], and they can be divided evenly among 2 packets.
If 3 packets are created, an additional 2, 2, 1, 0, 1 cards are needed, sum = 6 items. This yields quantities (6, 8, 12, 15, 18).
Any number of packets ≥ 2 can be created, but creating 2 packets requires the minimum number of additional cards.
Function Description
Complete the function carPackets in the editor below.
Function Parameters:
def carPackets(cardTypes: List[int]) -> int:
- cardTypes[n]: The quantity available of each card type.
Returns:
- int: The minimum number of additional cards to add.
Constraints
- 1 ≤ n ≤ 10⁶
- 1 ≤ cardTypes[i] ≤ 500
Input Format for Custom Testing
- The first line contains an integer, n, the size of the cardTypes array.
- Each line of the n subsequent lines (where 0 ≤ i < n) contains an integer cardTypes[i].
Sample Case
Input:
5
3
8
7
6
4
Output:
2
Explanation:
For 2 packets, add (1, 0, 1, 0, 0) cards to get (4, 8, 8, 6, 4).
For 3 packets, add (2, 2, 1, 0, 1) cards to get (6, 8, 12, 15, 18).
Any number of packets ≥ 2 can be created, but making 2 packets requires the minimum number of additional cards.
3. Connected Groups
Relationships between people may be represented in a matrix as a series of binary digits. For example, the direct relationships for person 0 with persons 0 through 5 might be shown as [1 0 1 0 0]. This means that person 0 knows persons 2 and 3, at the indices of each of the 1 values.
A relationship is transitive. In other words, if person 0 knows person 2 and person 2 knows person 3, then person 0 knows person 3 through person 2.
A group is composed of all the people who know one another, whether directly or transitively.
Example
Input Relationship Matrix
0 1 2
0 1 1 0
1 1 1 0
2 0 0 1
Persons 0 and 1 are connected, while person 2 is not.
There are 2 groups.
Function Description
Complete the function countGroups in the editor below.
Function Parameters:
def countGroups(related: List[str]) -> int:
- related[n]: An array of strings of binary digits related[i] that represent connections of people.
Returns:
- int: An integer that represents the number of groups of people.
Constraints
- 1 ≤ n ≤ 300
- 0 ≤ i < n
- |related[i]| = n
- Each related[i] contains a binary string of n zeros and ones.
- related is a square matrix.
我们长期稳定承接各大科技公司如TikTok、Google、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.
