[adobe] summer intern OA

Question 1

Given an array of distinct integers, determine the minimum absolute difference between any two elements. Print all pairs of elements with that difference, ensuring the smaller number appears first in each pair, and the pairs are sorted in ascending order.

Example
numbers = [6, 2, 4, 10]
The minimum absolute difference is 2 and the pairs with that difference are (2,4) and (4,6).

2 4  
4 6  

Function Description
Complete the function closestNumbers in the editor.

closestNumbers has the following parameter(s):

  • int numbers[n]: an array of integers

Returns
NONE

Prints
Distinct element pairs that share the minimum absolute difference, displayed in ascending order with each pair separated by one space on a single line.

Constraints

  • 2 ≤ n ≤ 10^5
  • -10^9 ≤ numbers[i] ≤ 10^9

Question 2

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, 5, 2]  

Aligned by index, the 3 coordinates are (0,0), (3,5), (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.

getTriangleArea has the following parameter(s):

  • int x[3]: An integer array that denotes the x coordinates.
  • int y[3]: An integer array that denotes the y coordinates, aligned with x by index.

Returns

  • long int: the area of the triangle

Constraints
All areas will be whole numbers.


Question 3

A design package needs a feature to dynamically center-align product names based on a designated display width on a website. To accomplish this, they add periods to both ends of the product name to ensure precise alignment to the width of a field, with a bias toward the left. If the number of periods needed is odd, the left side has one more period than the right.

Given a cell width and a list of n strings, width, and content[n], return a list of centered strings.

Example

width = 11  
content = ["Middle"]  

"Middle" has 6 letters, and is centered in 11 positions. There should be 5 periods total, 3 on the left and 2 on the right, i.e.,

...Middle..

Function Description
Complete the function centerDisplay in the editor below.

centerDisplay has the following parameter(s):

  • int width: the maximum width of every line
  • str content[n]: the strings to center

Returns

  • str[n]: a list of centered strings

Constraints

  • 1 ≤ width * n ≤ 2 * 10^5
  • 1 ≤ total number of characters in content ≤ 2 * 10^5
  • The length of each content[i] ≤ width
  • Strings consist of uppercase and lowercase English letters only.

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