โ† Back to all recaps

๐Ÿšจ Uber 2026 OA Full Breakdown: Binary Operations + Monotonic Stack + Balanced Subarray + Digit Swap Pairs โ€” 22 Minutes, 4 Problems AC!

3 min read

Manufacturing Anxiety: Breaking the Illusion

Recently tackled Uber 2026 OA, platform is still CodeSignal, 4 problems, 70 minutes to complete.

Honestly, for those with decent fundamentals, these problems feel very familiar. I finished all of them in just 22 minutes. Two out of four problems were practically free points โ€” you could write the solution at first glance, zero difficulty.

To help everyone practice ahead, I've compiled the approach and solution for each problem.


Uber 2026 OA Interview Overview

Item Details
Platform CodeSignal
Questions 4 problems
Time 70 minutes
Difficulty Medium-high, but some problems can be solved quickly if familiar

Key Focus Areas

  • Binary operations and bit manipulation
  • Stack and monotonic stack techniques
  • Subarray and permutation verification
  • String operations and swap matching logic

Overall, Uber OA values logical clarity, correct thinking, and implementation speed more than algorithmic complexity, but details are easy to mess up.


Q1: Minimum Operations to Reduce Binary Number to Zero

๐Ÿ” Problem Description

Given a positive integer n, each operation can add or subtract 2^i (i โ‰ฅ 0). Find the minimum number of operations to reduce n to 0.

๐Ÿ“ Solution Approach

  1. Treat as binary processing
  2. Process each bit from LSB to MSB while maintaining carry
  3. Current bit value = original bit + carry
    • If value is 1: can subtract to remove, ops +1, or add to generate carry
    • If value is 2 (bit 1 + carry 1): just carry, no operation needed
  4. Accumulate operation count
  5. End when final carry is 0

๐Ÿ’ก Key Insight

  • Consecutive 1s in binary can be optimized via "add 1 to carry" then "subtract"
  • Example: 111 (7) โ†’ add 1 becomes 1000 (8) โ†’ subtract 8, total 2 operations
  • Direct subtraction: 111 โ†’ -4 โ†’ -2 โ†’ -1, needs 3 operations

๐Ÿง‘โ€๐Ÿ’ป Code Implementation

def min_operations_to_zero(n: int) -> int:
    """
    Uber OA: Minimum operations to reduce binary number to zero
    
    Args:
        n: Positive integer
    
    Returns:
        int: Minimum number of operations
    """
    operations = 0
    carry = 0
    
    while n > 0 or carry > 0:
        # Current bit value = original bit + carry
        current_bit = (n & 1) + carry
        
        if current_bit == 1:
            # Value is 1: need one operation (add or subtract)
            # Greedy: if next bit is also 1, choose add (generate carry, may merge consecutive 1s)
            next_bit = (n >> 1) & 1
            if next_bit == 1:
                # Add: generate carry
                carry = 1
            else:
                # Subtract: no carry
                carry = 0
            operations += 1
        elif current_bit == 2:
            # Value is 2: just carry, no operation
            carry = 1
        else:
            # Value is 0: no operation needed
            carry = 0
        
        n >>= 1
    
    return operations


# Test cases
print(min_operations_to_zero(7))   # 7 = 111 -> +1 = 1000 -> -8 = 0, Answer: 2
print(min_operations_to_zero(5))   # 5 = 101 -> -4 = 1 -> -1 = 0, Answer: 2
print(min_operations_to_zero(1))   # 1 = 1 -> -1 = 0, Answer: 1
print(min_operations_to_zero(15))  # 15 = 1111 -> +1 = 10000 -> -16 = 0, Answer: 2
print(min_operations_to_zero(10))  # 10 = 1010 -> -8 = 2 -> -2 = 0, Answer: 2

โš ๏ธ Tips

  • The key in binary bit processing is carry maintenance
  • Must traverse from LSB to MSB, otherwise operation count will be wrong
  • Drawing binary diagrams helps understand the operation logic quickly

Q2: Discounted Price Sum

๐Ÿ” Problem Description

Each item's selling price = original price โˆ’ the first item to the right with price โ‰ค current price (sell at original price if none exists).

Find total selling price and indices of items sold at original price.

๐Ÿ“ Solution Approach

  1. Traverse items from right to left
  2. Use monotonic increasing stack to find first item to right with price โ‰ค current
  3. Stack empty โ‡’ sell at original price, record index
  4. Stack not empty โ‡’ selling price = original โˆ’ stack top price
  5. Accumulate total selling price
  6. Output total and original price indices (ascending order)

๐Ÿง‘โ€๐Ÿ’ป Code Implementation

def discounted_price_sum(prices: list) -> tuple:
    """
    Uber OA: Discounted price sum
    
    Args:
        prices: List of original prices
    
    Returns:
        tuple: (total selling price, list of original price indices)
    """
    n = len(prices)
    total = 0
    full_price_indices = []
    stack = []  # Monotonic increasing stack, stores (price, index)
    
    # Traverse from right to left
    for i in range(n - 1, -1, -1):
        current_price = prices[i]
        
        # Pop all elements greater than current price
        while stack and stack[-1][0] > current_price:
            stack.pop()
        
        if not stack:
            # Stack empty: sell at original price
            total += current_price
            full_price_indices.append(i)
        else:
            # Stack not empty: discount price = original - first โ‰ค price to right
            discount_price = current_price - stack[-1][0]
            total += discount_price
        
        # Push current element
        stack.append((current_price, i))
    
    # Sort indices ascending
    full_price_indices.sort()
    
    return total, full_price_indices


# Test cases
prices1 = [8, 4, 6, 2, 3]
print(discounted_price_sum(prices1))
# Analysis:
# i=4: 3, stack empty, original 3
# i=3: 2, stack empty, original 2
# i=2: 6, stack top 2 โ‰ค 6, price 6-2=4
# i=1: 4, stack top 2 โ‰ค 4, price 4-2=2
# i=0: 8, stack top 4 โ‰ค 8, price 8-4=4
# Total: 4+2+4+2+3 = 15, original indices: [3, 4]

prices2 = [5, 1, 4, 2]
print(discounted_price_sum(prices2))

โš ๏ธ Tips

  • Monotonic stack is the classic tool for "first element to right meeting condition"
  • Core is order and stack state maintenance
  • Remember to sort indices before output, otherwise may WA

Q3: Balanced Subarray

๐Ÿ” Problem Description

For each k (1 to n), determine if there exists a subarray that is exactly a permutation of 1 to k.

๐Ÿ“ Solution Approach

  1. First record each number's position pos[value]
  2. From k = 1, maintain the minimum interval [L, R] containing numbers 1 ~ k
    • L = min(pos[1..k])
    • R = max(pos[1..k])
  3. If R โˆ’ L + 1 == k, then k is balanced
    • Interval length equals k exactly, and value range is 1 ~ k, must be permutation
  4. Otherwise not balanced

๐Ÿง‘โ€๐Ÿ’ป Code Implementation

def balanced_subarray(arr: list) -> list:
    """
    Uber OA: Check if 1~k has balanced subarray
    
    Args:
        arr: Permutation of 1~n
    
    Returns:
        list: Boolean array of length n, result[i] indicates if k=i+1 is balanced
    """
    n = len(arr)
    
    # Record each number's position (1-indexed value -> 0-indexed position)
    pos = [0] * (n + 1)
    for i, val in enumerate(arr):
        pos[val] = i
    
    result = []
    min_pos = float('inf')
    max_pos = float('-inf')
    
    for k in range(1, n + 1):
        # Update interval range containing 1~k
        min_pos = min(min_pos, pos[k])
        max_pos = max(max_pos, pos[k])
        
        # Check if interval length exactly equals k
        interval_len = max_pos - min_pos + 1
        if interval_len == k:
            result.append(True)
        else:
            result.append(False)
    
    return result


# Test cases
arr1 = [3, 1, 2, 5, 4]
print(balanced_subarray(arr1))
# k=1: pos[1]=1, interval[1,1], len=1 โœ“
# k=2: pos[2]=2, interval[1,2], len=2 โœ“
# k=3: pos[3]=0, interval[0,2], len=3 โœ“
# k=4: pos[4]=4, interval[0,4], len=5 โ‰  4 โœ—
# k=5: pos[5]=3, interval[0,4], len=5 โœ“
# Output: [True, True, True, False, True]

arr2 = [2, 1, 4, 3]
print(balanced_subarray(arr2))
# k=1: pos[1]=1, interval[1,1], len=1 โœ“
# k=2: pos[2]=0, interval[0,1], len=2 โœ“
# k=3: pos[3]=3, interval[0,3], len=4 โ‰  3 โœ—
# k=4: pos[4]=2, interval[0,3], len=4 โœ“
# Output: [True, True, False, True]

โš ๏ธ Tips

  • Key is recording number positions and maintaining interval min/max
  • Can cumulatively update min/max during traversal, no need for repeated scans
  • This problem is perfect for array + index mapping, time complexity O(n)

Q4: Maximum Pairs by Swapping Digits

๐Ÿ” Problem Description

Two numbers can form a pair if they can become each other through at most two swaps of digit positions (including already equal). Find total number of pairs.

๐Ÿ“ Solution Approach

  1. Different lengths โ‡’ cannot pair
  2. Same length:
    • Convert numbers to strings and sort characters
    • If sorted strings are same โ‡’ can become each other through swaps (count)
    • If sorted strings differ:
      • Count differing positions
      • If diff positions โ‰ค 4 and chars can match pairwise โ‡’ can do two swaps
  3. Implementation:
    • Group by length first
    • Within group, use hash table to count sorted string frequency for equal pairs
    • For unequal cases, check if two-swap condition is met

๐Ÿง‘โ€๐Ÿ’ป Code Implementation

from collections import defaultdict

def max_pairs_by_swapping(nums: list) -> int:
    """
    Uber OA: Maximum pairs with at most two swaps
    
    Args:
        nums: List of numbers
    
    Returns:
        int: Total number of pairs
    """
    # Group by length
    length_groups = defaultdict(list)
    for num in nums:
        s = str(num)
        length_groups[len(s)].append(s)
    
    total_pairs = 0
    
    for length, group in length_groups.items():
        n = len(group)
        
        # Count strings with same sorted chars (can become each other via swaps)
        sorted_count = defaultdict(int)
        for s in group:
            sorted_s = ''.join(sorted(s))
            sorted_count[sorted_s] += 1
        
        # Calculate pairs with same sorted string: C(count, 2) = count * (count - 1) / 2
        for count in sorted_count.values():
            total_pairs += count * (count - 1) // 2
    
    return total_pairs


def can_match_with_two_swaps(s1: str, s2: str) -> bool:
    """
    Check if two strings can become each other with at most two swaps
    """
    if len(s1) != len(s2):
        return False
    
    # Find differing positions
    diff_positions = []
    for i in range(len(s1)):
        if s1[i] != s2[i]:
            diff_positions.append(i)
    
    # 0 differences: already equal
    if len(diff_positions) == 0:
        return True
    
    # 2 differences: one swap
    if len(diff_positions) == 2:
        i, j = diff_positions
        return s1[i] == s2[j] and s1[j] == s2[i]
    
    # 4 differences: two swaps (need to check if chars match)
    if len(diff_positions) == 4:
        chars1 = [s1[i] for i in diff_positions]
        chars2 = [s2[i] for i in diff_positions]
        return sorted(chars1) == sorted(chars2)
    
    return False


# More precise version (checks each pair for swap possibility)
def max_pairs_precise(nums: list) -> int:
    """
    Precise version: check if each pair can match with at most two swaps
    """
    n = len(nums)
    pairs = 0
    
    for i in range(n):
        for j in range(i + 1, n):
            s1, s2 = str(nums[i]), str(nums[j])
            if can_match_with_two_swaps(s1, s2):
                pairs += 1
    
    return pairs


# Test cases
nums1 = [123, 321, 132, 456]
print(max_pairs_by_swapping(nums1))  # 123, 321, 132 can pair with each other, 3 pairs

nums2 = [111, 111, 111]
print(max_pairs_by_swapping(nums2))  # 3 identical, C(3,2) = 3 pairs

nums3 = [12, 21, 34, 43, 56]
print(max_pairs_by_swapping(nums3))  # (12,21), (34,43) = 2 pairs

โš ๏ธ Tips

  • Sorting string chars quickly determines if swap transformation is possible
  • Diff positions โ‰ค 4 is the key condition
  • Hash table grouping significantly reduces time complexity

Complexity Analysis

Problem Time Complexity Space Complexity
Q1: Binary to Zero O(log n) O(1)
Q2: Discounted Price O(n) O(n)
Q3: Balanced Subarray O(n) O(n)
Q4: Max Pairs O(nยฒ ร— L) or O(n ร— L log L) O(n ร— L)

Where L = maximum number of digits


๐Ÿ”ฅ Why Most People Fail

Common Mistake Correct Approach
Q1 forget carry handling Maintain carry variable
Q1 process from MSB Must traverse from LSB to MSB
Q2 wrong monotonic stack direction Traverse from right to left
Q2 indices not sorted Sort ascending before output
Q3 repeated scanning for min/max Cumulatively update min_pos, max_pos
Q4 only consider equal case Also consider 2 and 4 diff positions

FAQ | Uber 2026 OA Common Questions

Q1: How many problems in Uber 2026 OA? What's the difficulty?

Uber 2026 OA has 4 problems, including binary min operations, monotonic stack discount price, subarray permutation check, and max digit swap pairs. Difficulty is medium-high, but most are common template problems. With familiarity with CodeSignal and Python solving approaches, you can usually finish quickly.

Q2: How long does Uber 2026 OA take to complete?

Based on real experience, if familiar with problem types, all four can be done in 20-30 minutes. I personally finished the whole set in 22 minutes first try. Proper problem ordering and using Python template code can significantly save time.

Q3: What are Uber 2026 OA's focus areas?

Main abilities tested:

  • Binary bit operations and carry handling
  • Monotonic stack application and discount calculation logic
  • Subarray permutation check and interval min/max maintenance
  • String-number matching and at-most-two-swap logic

Also tests edge case handling, complexity understanding, and implementation ability.

Q4: What are Python's advantages in Uber OA?

Python's concise syntax and built-in data structures (dict, list, set) and functions (min, max, sorted) are perfect for OA logic, especially:

  • Binary bit operations and carry simulation
  • Monotonic stack operations
  • Index mapping and subarray checking
  • String conversion and hash counting

Using Python templates properly improves speed and accuracy.

Q5: Any tips for passing Uber OA quickly?

Summary:

  • Familiarize with template types: binary processing, monotonic stack, interval checking, char swap matching
  • Clarify logic before coding: sketch or test with small examples
  • Allocate time wisely: do familiar problems first, leave hard ones for last
  • Review edge cases: especially swap count, carry, index bounds, char matching
  • Reuse template code: prepare utility functions in advance

Q6: Do Uber OA problems repeat?

Based on real experience, CodeSignal platform problems have high type repetition, especially classic templates like binary operations, monotonic stack, and subarray permutations. Practicing these types ahead and understanding general solutions and edge handling greatly improves AC rate.


๐Ÿ“ž oavoservice Services

Stop wasting time! Uber / TikTok / Stripe OA Quick Pass Guide.

Many students can actually solve problems, but OA time pressure is too high and details trip them up.

For this, we provide mature big company OA support solutions:

  • โœ… OA Assistance: CodeSignal / HackerRank / Nowcoder perfect score guarantee
  • โœ… Test Support: Quick handling of high-frequency problem types
  • โœ… Remote seamless operation: Traceless process, stable execution
  • โœ… Goal: Help you nail the critical OA stage first try, reduce unnecessary effort

๐Ÿ‘‰ Add WeChat Now: Coding0201

Don't let 4 OA problems ruin your Uber Offer.


Original content by oavoservice team. Please credit when sharing.


่”็ณปๆ–นๅผ

Email: [email protected] Telegram: @OAVOProxy