Amazon interview question

They asked me to solve a hard LeetCode question