cswork / OAOpen practice workspace

Valkyrie TradingOA #2

BST Path Distance Between Two Values

Estimated MediumStatement and editorial — judging is being prepared

Topics (AI-labelled)BST

Construct a binary search tree from a list of integers in the order given (no balancing, no duplicates). Then return the distance (number of edges) between two nodes with given values. If either value is missing, return -1.

Examples:

  • strArr = ["1","2","3","4"], u = 4, v = 2 → 2
  • strArr = ["1","2","3","4"], u = 4, v = 0 → -1
  • [8,7,13,6,2,5,1,9,11,3,4,10], u = 4, v = 2 → 3

Editorial

Loading solution…