Implement frequency + distance top‑K queries | Google Interview Question