Count Boomerang Triples Among Pinned Places on a Map

Last updated: November 29, 2026

Quick Overview

Given n distinct map pins as integer coordinates, count ordered triples (i, j, k) where pin i is the same distance from pin j as from pin k.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


Given n distinct map pins as integer coordinates, count ordered triples (i, j, k) where pin i is the same distance from pin j as from pin k.

A Google technical screen hashing question themed on Google Maps pins. The interviewer wants the shift from O(n^3) to O(n^2) by fixing the center pin and hashing squared distances, plus the observation that order matters so each group of m equal distances contributes m(m-1).

What the Interviewer Expects
  • Fixes the center point and hashes distances to all others
  • Uses squared distances to avoid floating point
  • Counts ordered pairs as m(m-1) per distance bucket
  • States O(n^2) time and O(n) space per center
  • Handles n < 3
Key Topics to Cover
Hash Map
Geometry
Counting Pairs
Squared Distance
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Count unordered triples instead; what changes?
  • How would you count isosceles triangles, excluding collinear triples?
  • Scale to millions of pins where O(n^2) is too slow; what approximation or spatial index would help?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements
  • Input: list of distinct (x, y) integer pairs.
  • Output: number of ordered triples (i, j, k) with j != k and dist(i, j) == dist(i, k).
  • n up to around 500, so O(n^2) is fine and O(n^3) is no...
High-Level Design

Fix the center pin i. Compute the squared distance from i to every other pin and count how many pins share each distance. If m pins are at the same distance, they form m(m-1) ordered (j, k) pairs. Sum...


Submit Your Answer
Markdown supported