Amazon Interview Question

2 Complex algorithm to solve under 1 hour