Amazon Interview Question

complex data structure problem