Cresta NG OA – 2024北美秋招笔试真题 – OA writing 代写 – 面试辅助 – 代面试 – VO interview support – 一亩三分地

1. Question 1

An intern at HackerRank is assigned the task of finding the optimal middle subsequence.

An optimal middle subsequence is a subsequence chosen[] of length 3 chosen from an array arr, such that:

  • chosen[0] < chosen[1] > chosen[2]
  • The sum of its elements is the minimum possible.

Problem

Given an array, return the sum of the values of the optimal middle subsequence. If there is none, return -1.

Note

A subsequence of an array is obtained by deleting some (possibly 0) elements from the array without changing the order of the remaining elements. For example:

  • [1, 3] is a subsequence of [1, 2, 3, 4]
  • [4, 2] is not.

Example

For n = 7 and arr = [3, 4, 5, 1, 2, 3, 1]:

  • A valid subsequence [1, 2, 1] can be chosen:
    • 1 < 2 > 1
    • Sum = 1 + 2 + 1 = 4, which is the minimum possible.

Thus, the answer is 4.

Function Description

Complete the function getMinimumSum in the editor below.

def getMinimumSum(arr: List[int]) -> int:
# Complete this function

2. Question 2

The country of Hackerland can be represented as a directed graph of city_nodes cities and city_edges uni-directional roads with cities indexed from 1 to city_nodes. The i-th road is a uni-directional road from city_from[i] to city_to[i]. The city indexed c is the capital of the country.

Problem

The king of the country wants to construct new roads such that all cities are reachable from the capital city. Find the minimum number of uni-directional roads required to be built such that all cities are reachable from the capital city.

Example

For city_nodes = 6, city_edges = 2, city_from = [4, 5], city_to = [1, 2], and c = 6:

  • One optimal set of roads is:
    1. Build a road from city 6 to city 3.
    2. Build a road from city 5 to city 4.
    3. Build a road from city 3 to city 5.

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