Quickselect, distance between tree nodes, and substrings with a prefix

0
Remix

Three problems from one loop:

  1. Find the k-th largest element with quickselect. Compare the approaches and how to choose the pivot, then implement one.
  2. Given the edges of a tree and two nodes, return how far apart they are. Clarify duplicate edges, whether the edges always form a tree, and missing or identical nodes.
  3. Given a string and a target, count the substrings that start with the target. Follow-up: the length of the shortest substring that contains the target.
GoogleCodingLast asked Apr 2026
No answer yet. Write the first one; the best answer gets endorsed.