Amazon interview question

In OA I have two tasks for the specific algorithms