Sharing of Uber OA real questions | Monotone stack + Interval continuity judgment ideas dismantling | Complete review of three questions

46 Views
No Comment

Uber OA has just ended, so I’ll write and share while it’s hot to build up my character. My game has a three-question structure, and the overall difficulty level is roughly as follows: People with a solid foundation will find it smooth, while people who usually only answer scattered questions may find it a bit stuck. Let’s talk about the idea below.

Question 1: Minimum number of power operations

Given a positive integer N, each operation can add or subtract an integer power of 2 (2^i,I≥0).

Requirements: The calculation will N Become 0 Minimum number of operations required.

Question 1: Minimum number of power operations

Problem-solving ideas

The goal of the addition and subtraction operations is to maximize the elimination of 1 in the binary representation. When the last two digits are 11, perform a +1 operation to eliminate consecutive 1s. When the last two digits are 01, perform a -1 operation to eliminate a single 1. When the last two digits are 0, directly shift one to the right. Continuously check the last two digits of the binary representation of the value: 11 → perform +1, 01 → perform -1, 0X → shift one to the right. Until the value reaches zero, count the total number of operations.

Topic 2: Calculation of final product pricing

Given an array of product prices, the final price of each product = original price – the first one on the right ≤ its price (if not, the original price will be used).

Requirements: Output the sum of the final price of all items, and the 0-based index (space separated in ascending order) of the items sold at their original price.

Topic 2: Calculation of final product pricing

Problem-solving ideas

For each p[i], if there is one less than or equal to it on its right, then find the first p[j] that is less than or equal to it, and the value of p[i] will become p[i] – p[j], otherwise it will remain unchanged. Let us output all the final values ​​and the item subscripts that have not changed, and just use a monotonic stack to maintain it.

Question 3: Balanced Number Determination

Given a permutation array p of 1~n, if there is an interval [l,r] such that the numbers in the interval are exactly permutations of 1~k, then k is a balanced number.

Requirement: Determine whether each k from 1 to n is balanced, and return a binary string of length n (the k-th bit is 1 to indicate balance, and 0 to indicate balance).

Question 3: Balanced Number Determination

Problem-solving ideas

Consider asking us to find 1~n. For each i, does [1,i] all appear in an interval, and there are no other numbers. Obviously [1,i] can be pushed to [1,i + 1], and is only related to the left and right endpoints [l,r] of [1,i]. We maintain a leftmost and rightmost. If r – l + 1 is exactly equal to i, then it is legal, otherwise it is illegal.

Learn more

If you are preparing for OA from major companies such as Uber/TikTok/Microsoft, it is recommended that you do targeted training in advance. It’s not that many students don’t know how to do it, but that the models are unfamiliar, the time allocation is unreasonable, and the details are not stable enough. We provide systematic preparation of real questions,OA traceless assist , help you perform stably under the real exam rhythm and improve your passing rate.

author avatar
Jory Wang Amazon Senior Software Development Engineer
Amazon senior engineer, focusing on the research and development of infrastructure core systems, with rich practical experience in system scalability, reliability and cost optimization. Currently focusing on FAANG SDE interview coaching, helping 30+ candidates successfully obtain L5/L6 Offers within one year.
END
 0