weride oa | weride 面经 | weride SDE | OA辅助 | 一亩三分地

weride oa | weride 面经 | weride SDE | OA辅助 | 一亩三分地

Weride 这三年在稳步发展,是自动驾驶领域的头部企业之一。融资和商业化情况非常不错,已经进入pre-IPO阶段。目前在中国、 美国、新加坡都有分部。 国总部位于San Jose, 工作环境良好,同事优秀,提供免费午餐晚餐,有许多机会回国出差。 今年也扩大了NG和intern的规模,目前还有大量的HC。现在的大环境对于NG/Intern来说比较困难,所以来给大家撑伞啦。 这篇文章分享一些我们亲身总结的 weride oa 面经。

Weride OA Question 1: Distance Metric

For each element in a given array, calculate the absolute value of index differences between it and all other elements of the same value. Return theresulting values in an array.

For example, if the array elements at indices 2 and 3 are equal, the distance metric for element 2 is ∣3−2∣=1|3 – 2| = 1. Forelement 3 it is ∣3−2∣=1|3 – 2| = 1.

Example:

Input:

n = 6
arr = [1, 2, 1, 2, 1, 3]

The element arr[0] = 1. Similar elements are at indices 2 and 4.
Distance metric for arr[0]: ∣0−2∣+∣0−4∣=5|0 – 2| + |0 – 4| = 5.

Solve question:

Distance metric for each element:

  • The distance metric for arr[0] = 1: ∣0−2∣+∣0−4∣=5.
  • The distance metric for arr[1] = 2: ∣1−3∣=2.
  • The distance metric for arr[2] = 1: ∣2−0∣+∣2−4∣=4.
  • The distance metric for arr[3] = 2: ∣3−1∣=2.
  • The distance metric for arr[4] = 1: ∣4−0∣+∣4−2∣=6.
  • The distance metric for arr[5] = 3: No other similar elements. Distance = 0.

Resulting distance metrics: [5, 2, 4, 2, 6, 0].


Function Description

Complete the function getDistanceMetrics in the editor below.

Function Signature

def getDistanceMetrics(arr: List[int]) -> List[int]:

Parameters

  • arr (List[int]): An array of integers.

Returns

  • List[int]: An array of integers representing the sum of the distance metrics for each element in arr.

Weride OA Question 2: Bob Navigates a Maze

Bob and Alice have teamed up on a game show. After winning the first round, they now have access to a maze with hidden gold. If Bob can collect all the gold coinsand deliver them to Alice’s position, they can split the gold. Bob can move horizontally or vertically as long as he stays within the maze, andthe cell is not blocked.

The maze is represented by an n×m grid, where each cell has a value:

  • 0: Open cell
  • 1: Blocked cell
  • 2: Open cell containing a gold coin

Bob starts at the top-left corner of the maze at cell (0,0), and Alice’s position is given by (x,y). Determine the shortest path Bob can follow to:

  1. Collect all the gold coins in the maze.
  2. Deliver the coins to Alice at (x,y).

If it is impossible for Bob to collect all the gold coins or deliver them to Alice, return -1.

Example: maze = [[1,0,2],[1,2,0],[1,0,0]] with Alice at (2,2).

weride oa 1 example

B represents Bob’s starting position at (0,0), and A represents Alice’s position (which will also be Bob’sfinal position). As Bob starts at (0,0), he has two possible paths to collect the gold coins and deliver them to Alice:

  1. (0,0)→(0,1)→(1,1)→(2,1)→(2,2)
  2. (0,0)→(0,1)→(1,1)→(1,2)→(2,2)

Both paths have a length of 4 and represent the shortest path.


Function Description

Complete the function minMoves in the editor below. The function must return the integer length of Bob’s shortest path to collect all gold coins and deliver them to Alice, or -1 if it is not possible.

Function Signature

def minMoves(maze: List[List[int]], x: int, y: int) -> int:
    # Your implementation here

Parameters

  • maze: A 2D array of integers representing the maze.
  • x: An integer denoting Alice’s row coordinate.
  • y: An integer denoting Alice’s column coordinate.

Approach

  1. Record the positions of all the gold coins and use a binary representation to track the collection state of each coin.
  2. Use Breadth-First Search (BFS) starting from the initial position (0,0). At each step, track the current position, the state of collected coins, and the current step count.
  3. For each position, try moving in four directions (up, down, left, right). Update the state of collected coins and mark visited states.
  4. If Bob reaches Alice’s position and has collected all the gold coins, return the current step count. Otherwise, continue the search.
  5. If the search completes without meeting the conditions, return -1.

Weride OA Question 3: Discount Events

A general store at Hackerland sells n items with the price of the i-th item represented by price[i]. The store adjusts the prices of items based on inflation as queries of two types:

  1. 1 x v: Change the price of the x-th item to v.
  2. 2 v: Change any price that is less than v to v.

Given an array price of n integers and the price adjustment queries, return the final prices of all items.


Example

Input:

n = 3 price = [7, 5, 4] q = 3 queries = [[2, 6, 0], [1, 2, 9], [2, 8, 0]]

Explanation of queries:

  1. [2, 6, 0]: Change elements less than 6 to 6. Now price = [7, 6, 6].
  2. [1, 2, 9]: Change the 2-nd element to 9. Now price = [7, 9, 6].
  3. [2, 8, 0]: Change elements less than 8 to 8. Now price = [8, 9, 8].

Output:

[8, 9, 8]

Function Description

Complete the function getFinalPrice in the editor below.

Function Signature

def getFinalPrice(price: List[int], queries: List[List[int]]) -> List[int]:

Parameters

  • price (List[int]): An array of integers representing the prices of items.
  • queries (List[List[int]]): A 2D array where each query is represented as a list of integers.

Returns

  • List[int]: The final array of prices after all queries are executed.

Reference

WeRide interview questions

Weride | 一亩三分地

We provide services for writing online assessments (OA), proxy interviews, and interview assistance. For the OA writing service, we will ensure that youachieve a perfect score. Contact us now to make an appointment.

author avatar
ProgramHelp
END
 0
Comment(尚無留言)