Amazon interview question

Leetcode question similar to design twitter