Countries You Can Safely Invest In - Problem
Investment Opportunity Analysis

A telecommunications company is looking to expand their business globally! ๐ŸŒ They want to invest in countries where people talk more than the global average - because more talk time means more revenue potential.

You have access to three key data sources:

๐Ÿ“ž Person Table: Contains user information including phone numbers in format 'xxx-yyyyyyy' where 'xxx' is the 3-digit country code

๐ŸŒ Country Table: Maps country codes to country names

๐Ÿ“Š Calls Table: Contains call duration data between users

Your Mission: Find all countries where the average call duration is strictly greater than the global average call duration across all countries.

Key Insight: A call's country is determined by both the caller's and callee's country codes. You need to calculate the average duration for each country and compare it against the overall global average.

Input & Output

example_1.sql โ€” Basic Investment Analysis
$ Input: Person: [(1,'Jack','051-1234567'), (2,'Amy','051-1234568'), (3,'John','052-1234569')] Country: [('Peru','051'), ('USA','052')] Calls: [(1,2,59), (2,1,11), (1,3,20), (3,1,5), (2,3,1)]
โ€บ Output: ['Peru']
๐Ÿ’ก Note: Global average: (59+11+20+5+1)/5 = 19.2 minutes. Peru's calls: (59+11)/2 = 35 minutes average. USA's calls: (20+5+1)/3 = 8.67 minutes average. Only Peru (35 > 19.2) qualifies for investment.
example_2.sql โ€” Multiple Countries Above Average
$ Input: Person: [(1,'Alice','001-1234567'), (2,'Bob','002-1234568'), (3,'Carol','003-1234569'), (4,'Dave','001-1234570')] Country: [('CountryA','001'), ('CountryB','002'), ('CountryC','003')] Calls: [(1,2,100), (2,1,80), (3,4,60), (4,3,40), (1,4,30)]
โ€บ Output: ['CountryA', 'CountryB']
๐Ÿ’ก Note: Global average: (100+80+60+40+30)/5 = 62 minutes. CountryA: (100+80+30)/3 = 70 minutes. CountryB: (100+80)/2 = 90 minutes. CountryC: (60+40)/2 = 50 minutes. CountryA and CountryB exceed the global average.
example_3.sql โ€” No Investment Opportunities
$ Input: Person: [(1,'Eve','111-1111111'), (2,'Frank','222-2222222')] Country: [('Alpha','111'), ('Beta','222')] Calls: [(1,2,10), (2,1,10)]
โ€บ Output: []
๐Ÿ’ก Note: Global average: (10+10)/2 = 10 minutes. Both Alpha and Beta have exactly 10 minutes average call duration. Since we need STRICTLY greater than global average, no countries qualify.

Constraints

  • 1 โ‰ค Person.id โ‰ค 1000
  • Person.phone_number format: 'xxx-yyyyyyy' where x and y are digits
  • Country.country_code format: 'xxx' where x is digits
  • 1 โ‰ค Calls.duration โ‰ค 1000
  • caller_id โ‰  callee_id (no self-calls)
  • Country average must be strictly greater than global average

Visualization

Tap to expand
Investment Analysis Workflow๐Ÿ“Š Raw Dataโ€ข Call Recordsโ€ข Person Infoโ€ข Country Codesโ€ข Phone Numbers๐Ÿ”— Join Tablesโ€ข Extract country codesโ€ข Map calls to countriesโ€ข Link caller & calleeโ€ข Preserve durations๐Ÿ“ˆ Calculate Averagesโ€ข Global average: 19.2minโ€ข Peru average: 35minโ€ข USA average: 8.7minโ€ข Compare results๐Ÿ’ฐ Investment Decisionโ€ข Peru: 35 > 19.2 โœ…โ€ข USA: 8.7 < 19.2 โŒโ€ข Result: Invest in Peruโ€ข ROI potential highGlobal Avg19.2 minPeru35 minUSA8.7 minโœ… INVEST INPERUAbove Average!Call Duration ComparisonBaselineInvestment TargetBelow Threshold๐Ÿ’ก Key: Focus on countries with above-average engagement
Understanding the Visualization
1
Data Integration
Combine call records with person and country information to create a comprehensive dataset
2
Country Classification
Extract country codes from phone numbers and map calls to their respective countries
3
Average Calculations
Calculate both global average and individual country averages simultaneously
4
Investment Decision
Identify countries where average call duration exceeds the global benchmark
Key Takeaway
๐ŸŽฏ Key Insight: By identifying countries with above-average call durations, telecommunications companies can strategically invest in markets with higher customer engagement and revenue potential.
Asked in
Amazon 45 Google 38 Microsoft 32 Meta 28
47.2K Views
Medium-High Frequency
~15 min Avg. Time
1.8K Likes
Ln 1, Col 1
Smart Actions
๐Ÿ’ก Explanation
AI Ready
๐Ÿ’ก Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen