Solve linked list, grid BFS, and median queries | Apple Interview Question