[Mathworks] EDG intern OA
  1. Racers Selection

HackerLand Sports Club wants to send a team for a relay race. There are n racers in the group indexed from 0 to n - 1. The i-th racer has a speed of speed[i] units.

The coach decided to send some contiguous subsegments of racers for the race i.e. racers with index i, i + 1, i + 2, ... j such that each racer has the same speed in the group to ensure smooth baton transfer. To achieve the goal, the coach decided to remove some racers from the group such that the number of racers with the same speed in some contiguous segment is maximum.

Given the array, racers, and an integer k, find the maximum possible number of racers in some contiguous segment of racers with the same speed after at most k racers are removed.

Example

Suppose n = 6, k = 2, and speed = [1, 4, 4, 2, 2, 4].


The neural network of a virtual world is represented as a connected directed graph data structure, g. It has n nodes numbered from 1 to n, and n-1 edges, where the i-th edge connects node g_from[i] to g_to[i].

Select any node as root then reverse as many edges as necessary to have all edges flowing down, that is, away from the root. Choose a root that requires the minimum number of changes and report that number of changes.

Example

Given, g_nodes = 4, g_from = [1, 2, 3], and g_to = [4, 4, 4]. The tree can be visualized as:

          2
          ↓
   3  →  4  ←  1

One of the optimal strategies is to select node 3 as root and reverse one edge.


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