Amazon interview question

it was a leetcode question