Amazon interview question

Two algorithm problems average medium difficulty