cswork / libraryOpen practice workspace

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:

  1. Max profit from one stock trade
  • Input: an integer array prices, where prices[i] is the stock price on day i.
  • 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.
  1. 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 col to rightmost.
    • Within each column, order nodes by row ascending (top to bottom).
    • If multiple nodes share the same (row, col), order those nodes by their value ascending.
  • Output: a list of lists of node values following this ordering.

Community answers

Nothing here yet.

Join in on CSWork →