Uber Coding questions OA
Summary
I recently completed the online assessment for Uber, which featured two distinct coding challenges: a Word Wrap problem with a dash-separated output and a Nearest Exit problem on a 2D board.
Full Experience
I took the online assessment for Uber for a role in San Francisco. The assessment presented two primary coding questions. The first involved a Word Wrap problem where I had to format a list of words into lines of a maximum length, separated by dashes. The second question was a maze-solving problem, specifically finding the nearest exit from a given entry point on a 2D board with obstacles.
Interview Questions (2)
Given a list of words and a max line length, create a function that returns a wrapped list with dash separated words.
EXAMPLE
input:
["Tom","is","a","dragon","that","breathes","fire"]
maximum length of characters per line = 9
output:
["Tom-is-a-",
"dragon-t-",
"hat-brea-",
"thes-fire"]
There is an m x n rectangular 2d array called board which has rows and columns containing '0' or '+' only.
Rows and columns start at index 0.
The '0' value means it is a passable path whereas the '+' value is a wall that cannot be crossed.
You are a snake that can move in four directions- up, down, left, right. Entering and exiting the board must only happen at a '0' value. You can enter the board from any four sides/borders.
After entering the board, there can be multiple exits. Find the nearest exit.
EXAMPLE
+ 0 0 + + +
- 0 0 0 + +
-
-
- 0 + +
-
0 + + 0 + 0 0 0 0 0 0 0 + + +
board = [
['+', '0', '0', '+', '+', '+'],
['+', '0', '0', '0', '+', '+'],
['+', '+', '+', '0', '+', '+'],
['+', '+', '+', '0', '+', '+'],
['0', '+', '0', '0', '0', '0'],
['0', '0', '0', '+', '+', '+']
]find_exit(board, (4, 5))OUTPUT
(5,2)EXPLANATION
You are given the board array and a set of coordinates. 4 is the rowId, 5 is the columnId for entry. There are multiple exits. The goal is the find the nearest exit. Exit is at row 5 column 2. Answer is (5,2).