Uber Coding questions OA
Anonymous User
4311
Apr 07, 2021
Apr 23, 2021

These questions were asked by Uber Online Assessment San Francisco location

QUESTION 1: WORD WRAP
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"]

QUESTION 2: NEAREST EXIT
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)

Comments (9)