The Symmetric Coordinates interview question is a SQL-based challenge that focuses on identifying pairs of matching values in a table. You are typically given a table Functions with two columns, X and Y. Two pairs (X1, Y1) and (X2, Y2) are considered symmetric if X1 = Y2 and X2 = Y1. Your goal is to output all unique symmetric pairs (X, Y) where X <= Y, sorted by X.
This question is asked by companies like Mitsogo to test a candidate's SQL proficiency, specifically regarding self-joins and grouping. It evaluates whether you can handle cases where a pair might be its own symmetric partner (e.g., X=10, Y=10). It requires a combination of joining, filtering, and aggregation to ensure that you don't overcount or miss any valid pairs based on the problem's specific constraints.
The primary pattern is the Database Self-Join and Filtering.
f1.X = f2.Y and f1.Y = f2.X.X <= Y requirement, you add a filter f1.X <= f1.Y.X = Y, you need to check if that specific pair appears at least twice in the original table. This is often handled using a GROUP BY and HAVING COUNT(*) > 1 logic within the join or as a separate union.Input:
The most frequent mistake is not handling the X = Y case correctly. If you just join where f1.X = f2.Y and f1.Y = f2.X, a single row of (10, 10) will join with itself, but it doesn't have a distinct symmetric partner unless there is a second (10, 10) row. Another error is forgetting to sort the final output or failing to filter for X <= Y, leading to duplicate pairs in different orders (e.g., both (23, 25) and (25, 23)).
To excel in the Symmetric Coordinates coding problem, practice writing CTEs or subqueries to isolate counts of each pair. Understanding the Database interview pattern for self-joins is essential. Also, make sure you are comfortable with conditional logic in SQL, as you often need to treat X < Y and X = Y cases differently.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Active Businesses | Medium | Solve | |
| Active Users | Medium | Solve | |
| Activity Participants | Medium | Solve | |
| All People Report to the Given Manager | Medium | Solve | |
| All the Pairs With the Maximum Number of Common Followers | Medium | Solve |