Reviewed by Aditya Kumar · Last reviewed 2026-03-24
Produce unique pairs (A,B) with A<B. SQL: SELECT a.country c1, b.country c2 FROM countries a CROSS JOIN countries b WHERE a.country < b.country. Python: list(combinations(countries, 2)). Output: N*(N-1)/2 pairs. SCALABILITY: CROSS JOIN is O(n²)—avoid for large n; use sampling or...
Produce unique pairs (A,B) with A<B. SQL: SELECT a.country c1, b.country c2 FROM countries a CROSS JOIN countries b WHERE a.country < b.country. Python: list(combinations(countries, 2)). Output: N*(N-1)/2 pairs. SCALABILITY: CROSS JOIN is O(n²)—avoid for large n; use sampling or pre-aggregation. COST: Full cross join on 10K rows = 50M—consider incremental or partitioned approach for big data.
Red Flag: Producing (A,B) and (B,A) duplicates. Pro-Move: 'We add ORDER BY for reproducibility; use CROSS JOIN only for <1K rows; for larger we generate pairs in Spark with cartesian then filter.'
According to DataEngPrep.tech, this is one of the most frequently asked General/Other interview questions, reported at 1 company. DataEngPrep.tech maintains an editor-reviewed database of 1,863 data engineering interview questions across 7 categories.