Search Questions

Company: UBER

#1

Analyze the efficiency of the following sorting algorithm by counting the number of swaps it performs:

For an array `arr` of size `n`:
1. Find the smallest pair of indices 0 ≤ i < j ≤ n-1 such that arr[i] > arr[j], where "smallest" means lexicographical ordering of pairs (i1, j1) < (i2, j2) if i1 < i2 or (i1 = i2 and j1 < j2).
2. If no such pair exists, the algorithm stops.
3. Otherwise, swa

Asked in: UBER


Buyer: 0
Code Size:
#2

Bitwise Palindromic Paths

You are given a binary matrix of size N x M where each cell contains either 0 or 1. A path from the top-left cell (0,0) to the bottom-right cell (N-1,M-1) is valid if you can only move right or down at each step.

A path is called bitwise palindromic if the sequence of bits collected along the path forms a palindrome when interpreted as a string (e.g., 0110, 1, 101).

Asked in: UBER


Buyer: 0
Code Size:
#3

Q Trip Tag Generator Uber's platform auto-generates trip tags which are short strings summarizing key trip metadata. To validate the tagging logic, the infrastructure team is checking how many different ways a specific tag can be constructed using segments from historical tags.

You are given an array tags of length n, where each tag is a string of length m. You're also given a targetTag that ne

Asked in: UBER


Buyer: 0
Code Size:
#4

Fleet Upgrades

You're building a system for Uber Fleet Management to optimize vehicle upgrades within a limited operations budget.

There are a total of n vehicles where:
- `upgradeCost[i]`: cost to upgrade the i-th vehicle
- `expectedResale[i]`: expected resale value of the i-th vehicle after one year of operation

You may choose to upgrade any vehicle once, and the total upgrade cost mu

Asked in: UBER


Buyer: 0
Code Size:
#5

Q. Package Drop Optimization

Uber Connect's package delivery team is reviewing how delivery agents handle packages across multiple zones.

For each of the n delivery zones:
- `scheduledDrop[i]` stores the scheduled time (in minutes) to drop the package in the i-th zone.
- `realDrop[i]` stores the actual time (in minutes) the package was dropped in the i-th zone.

Due to system limitations

Asked in: UBER


Buyer: 0
Code Size:
#6

Academic Decathlon
Students are being selected for an academic decathlon team at a school. Each student has a skill level, and for a team to be uniform, the difference between any two consecutive skill levels (when arranged in increasing order) must be either 0 or 1.

Your task is to find the maximum possible team size.

Example
skills = [0, 12, 13, 9, 14]
Valid teams, when sorted, ar

Asked in: UBER


Buyer: 0
Code Size:
#7

Sum of Arrays
Given two arrays each of length n, arr1 and arr2, in one operation, any two elements of an array can be swapped. This can occur any number of times.

Find the maximum possible sum of i * (arr2[i] - arr1[i]) for all 1 ≤ i ≤ n after rearranging the arrays. Since the maximum possible sum can be large, return the value modulo (10^9 + 7).

Example
n = 4
arr1 = [2, 1, 3, 4]

Asked in: UBER


Buyer: 1
Code Size:
#8

Count Swaps During Custom Sorting
Analyze the efficiency of the following sorting algorithm by counting the number of swaps it performs:
For an array arr of size n:
1. Find the smallest pair of indices 0 ≤ i < j ≤ n-1 such that arr[i] > arr[j], where "smallest" means lexicographical ordering of pairs (i1, j1) < (i2, j2) if i1 < i2 or (i1 = i2 and j1 < j2).
2. If no such pair exists, th

Asked in: UBER


Buyer: 1
Code Size:
#9

Given a set of nodes and a list of connected pairs, determine the order (number of nodes) in each connected component in the graph. For each component, calculate the ceiling of the square root of its order, and return the sum of these values across all connected components.

Example
graph_nodes = 10
graph_from = [1, 1, 2, 3, 7]
graph_to = [2, 3, 4, 5, 8]

There are graph_edges = 5 ed

Asked in: UBER


Buyer: 0
Code Size: