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.
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
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.
๐ก
Explanation
AI Ready
๐ก Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code