Interview questions · Uber
Solve stock profit and vertical tree traversal
Assesses proficiency in array processing and binary tree traversal algorithms—specifically single-pass analysis of time-series data and coordinate-based vertical ordering of tree nodes; Category: Coding & Algorithms; Level of abstraction: implementation-level algorithmic coding.
You have a 60-minute coding interview with two algorithm questions:
- Max profit from one stock trade
- Input: an integer array
prices, whereprices[i]is the stock price on dayi. - Task: Choose one day to buy and a later day to sell to maximize profit. Return the maximum profit; if no profitable trade is possible, return
0.
- Vertical traversal of a binary tree
- Input: the root of a binary tree.
- Define coordinates: root at
(row=0, col=0), left child(row+1, col-1), right child(row+1, col+1). - Task: Return the nodes grouped by vertical columns from leftmost
colto rightmost.- Within each column, order nodes by
rowascending (top to bottom). - If multiple nodes share the same
(row, col), order those nodes by their value ascending.
- Within each column, order nodes by
- Output: a list of lists of node values following this ordering.
Community answers
Nothing here yet.
Join in on CSWork →