Uber Software Engineer Coding & Algorithms Interview Questions
Practice the exact questions companies are asking right now.
Find cheapest flight with at most K stops
Problem You are given a directed weighted graph representing flights between cities. Inputs - An integer n: number of cities, labeled 0..n-1. - A list...
Detect cycle in directed dependency graph
You are given a directed dependency graph representing services in a system. - There are n services, labeled from 0 to n - 1. - You are given a list o...
Compute exclusive execution time from logs
Problem You are given execution logs from a single-threaded CPU that runs n functions labeled 0..n-1. The CPU can run only one function at a time. A f...
Check feasibility of AI course schedule
You are designing a learning path for n AI-related courses, labeled from 0 to n - 1. Some courses have prerequisites. For example, to take course b, y...
Maximize stock profit with one or two trades
You are given an array prices where prices[i] is the price of a given stock on day i (0-indexed). You want to maximize your profit by choosing when to...
Implement three interview-style coding tasks
You are given three separate coding tasks, all focused on algorithm and data-structure design. --- Task 1: Longest Bounded-Difference Subarray You are...
Compute outer boundary of an N-ary tree
You are given the root of a rooted N-ary tree. Each node contains: - An integer value. - An ordered list of children from left to right (0 or more chi...
Minimize time using elevator then climb stairs
Problem You need to go up n floors (from floor 0 to floor n). You may: 1. Take the elevator first (at most once, only at the start) for k floors, wher...
Print directory tree with indentation
You are given a root directory of a filesystem represented as a tree. Each node is either a directory (can have children) or a file (no children). Pri...
Solve three algorithmic optimization and search problems
You are given three independent coding problems. --- Problem 1: Allocate tasks between two workers to maximize reward You have n independent tasks tha...
Compute build order from dependencies
Given a set of package build dependencies, output a valid build order so that each package is built only after all of its dependencies. The input is a...
Sort by squares and find k-th smallest
Given a nondecreasing sorted array of integers nums, do the following: 1) Reorder the original elements by increasing square value (equivalently, by a...
Find next and closest palindromes
Given a non-negative integer represented as a string n (no leading zeros unless n == "0"), return the smallest palindromic integer strictly greater th...
Simulate one-round color elimination on a grid
Given an m x n integer matrix board where board[r][c] > 0 represents a color and 0 represents empty: ( 1) A nonzero cell at (r,c) explodes in this rou...
Design top-K frequency structure
Design an in-memory data structure that supports: add(x) to observe an item, inc(x) to increment its frequency, dec(x) to decrement (deleting when zer...
Simulate views on an n-ary tree
Given a rooted, ordered n-ary tree (each node has a value and an ordered list of children), simulate an observer who starts at the bottom-left, moves ...
Implement binary search variants
Implement binary search on a sorted integer array without using library functions. Provide both iterative and recursive versions that: (a) return the ...
Simulate fixed-shape tiling on a grid
You are given an empty n-by-m grid and a list of tile patterns, patterns[0..k-1]. Each pattern is a binary matrix (1 = filled cell, 0 = hole) and must...
Find leftmost point of maximum brightness
You are given an array of lights, where each light is [p, r] representing a lamp centered at coordinate p on the real number line with radius r, illum...
Implement 2D word search variants and analyze complexity
Given an m x n grid of uppercase letters board and a string word, implement two related functions: ( 1) Fixed-direction search: Return true if word ap...