Amazon interview question

Coding interview had 2 problems with dsa.