Amazon Interview Question

very difficult questions in algorithms -2