Amazon Interview Question

In OA I have two tasks for the specific algorithms