Amazon interview question

A typical medium level algorithm you’d find on LeetCode or Hackerrank.