[C3AI] intern oa

As new students begin to arrive at college, each receives a unique ID number, 1 to n. Initially, the students do not know one another, and each has a different circle of friends. As the semester progresses, other groups of friends begin to form randomly.

There will be three arrays, each aligned by an index. The first array will contain a queryType which will be either Friend or Total. The next two arrays, students1 and students2, will each contain a student ID. If the query type is Friend, the two students become friends. If the query type is Total, report the sum of the sizes of each group of friends for the two students.

Example

The queries are assembled, aligned by index.

Explanation

There are n = 2 students labeled with the IDs {1, 2}. Perform the following q = 1 query:

  1. Total 1, 2: Find the total number of students in the collective friend groups of students 1 and 2. Student 1 is in a group with one friend (i.e., {1}), and student 2 is in a group with one friend (i.e., {2}), so store 1 + 1 = 2 in index 0 of the return array.

After performing all the queries, return the array [2] as the answer.


Given a square grid of integers and an integer value, maxSum, determine the maximum size of the square sub-grid where, for all such sub-grids, the sum of all its elements' values is less than or equal to the value maxSum.

Example:

grid = [[2, 2, 2], [3, 3, 3], [4, 4, 4]]
maxSum: Different scenarios shown below.

maxSum: The maximum sum of all square sub-grids of a size must be less than or equal to this integer value.

  1. The maximum 1x1 grid has a sum of 4. If maxSum < 4, there is no size square sub-grid that satisfies the condition. The answer is 0.
1 x 1 Sub-grids
Maximum sub-grid sum = 4
  1. 2 x 2 Sub-grids: Maximum sub-grid sum = 14
    Calculation: (3 + 3 + 4 + 4 = 14)
  1. The maximum 3x3 grid has a sum of 27. If 14 ≤ maxSum < 27, the maximum size of the square sub-grid is 2.

3 x 3 Sub-grids

Maximum sub-grid sum = 27
Calculation: (2 + 2 + 2 + 3 + 3 + 3 + 4 + 4 + 4 = 27)

Condition

If maxSum >= 27, the entire grid satisfies the condition, so the answer is 3.

Function Description

Complete the function largestSubgrid in the editor below.


我们长期稳定承接各大科技公司如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.

Leave a Reply

Your email address will not be published. Required fields are marked *