冲刺 Uber 秋招!真实 OA 编程题目大公开(含满分代码环境) – Uber OA 真题整理(共3题) – 一亩三分地

职位:Graduate Software Engineer I, iOS
平台:HackerRank
共3题 | 时长:120分钟


✅ Question 1: Final Price Calculation

A shopkeeper arranges items in a list for sale. Starting from the left, each item is sold at its full price minus the price of the first item to its right that is of equal or lower price. If no such item exists, the current item is sold at its full price.

Print the sum of the final cost for all items, then on the next line, print space-separated, 0-based indices of items that are sold at full price, in ascending order.


🧪 Example

For input prices: [2, 3, 1, 2, 4, 2]

  • Index 0: 2 → next lower/equal = 1 → discounted price = 2 - 1 = 1
  • Index 1: 3 → next lower/equal = 1 → discounted price = 3 - 1 = 2
  • Index 2: 1 → no lower → full price = 1
  • Index 3: 2 → next lower/equal = 2 → discounted = 2 - 2 = 0
  • Index 4: 4 → next lower/equal = 2 → discounted = 4 - 2 = 2
  • Index 5: 2 → no lower → full price = 2

Total cost = 1 + 2 + 1 + 0 + 2 + 2 = 8
Items sold at full price: indices [2, 5]

✅ Output:

8
2 5

🔧 Function Signature

def finalPrice(prices: List[int]) -> None:

📥 Input

  • prices (List[int]): array of item prices

📤 Output

  • Print total cost on the first line
  • Print space-separated indices of items sold at full price (ascending)

📏 Constraints

  • 1 ≤ n ≤ 10⁵
  • 1 ≤ prices[i] ≤ 10⁶

✅ Question 2: Maximum Number of Products

Alex is shopping at Ozone Galleria Mall, where each cubicle sells products at a fixed price in non-decreasing order left to right.

Alex can buy at most one product per cubicle from position pos to the end, and wants to maximize the number of products he can buy without exceeding a given amount.


🔧 Function Signature

def findMaximumValue(prices: List[int], pos: List[int], amount: List[int]) -> List[int]:

📥 Input

  • prices: List[int] — prices at each cubicle
  • pos: List[int] — starting position for each query (1-based index)
  • amount: List[int] — available money for each query

📤 Output

  • List[int] — maximum number of products Alex can buy per query

🧪 Example

Input:

prices = [3, 4, 5, 5, 7]
queries = [
    [2, 10],   # -> Can buy 2 items (4+5 or 5+5)
    [1, 24],   # -> Can buy all (3+4+5+5+7 = 24)
    [5, 5],    # -> Can't buy anything (price is 7 > 5)
]

Output:

[2, 5, 0]

📏 Constraints

  • 1 ≤ prices.length ≤ 10⁵
  • 1 ≤ prices[i] ≤ 10⁶
  • 1 ≤ pos.length == amount.length ≤ 10⁵

✅ Question 3: Count Balanced Numbers

Given a permutation p of length n, a number k is balanced if there exists a contiguous segment of size k in the permutation that forms a valid permutation of {1, ..., k}.

You need to return a binary string of length n, where ith character is '1' if k = i is balanced, and '0' otherwise.


🔧 Function Signature

def countBalancedNumbers(p: List[int]) -> str:

📥 Input

  • p: List[int] — a permutation of numbers from 1 to n (inclusive), no repeats

📤 Output

  • string — binary string indicating which lengths k are balanced

🧪 Example

Input:

p = [4, 1, 3, 2]

Check for k = 1 to 4:

  • k=1 → [1] → valid
  • k=2 → no segment with exactly [1,2]
  • k=3 → segment [1,3,2] → valid
  • k=4 → full array [4,1,3,2] → valid

Output: "1011"


📏 Constraints

  • 1 ≤ n ≤ 2 * 10⁵
  • 1 ≤ p[i] ≤ n
  • All p[i] are unique (valid permutation)

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