Implement cache and merge intervals | Microsoft Interview Question