Amazon interview question

Nothing was really that difficult. With basic algos and DS knowledge it is doable