Amazon interview question

it was similar to leetcode dsa problems