Number of Trusted Contacts

ASKED IN INTERVIEW
2pts
Whats App

Problem Statement

WhatsApp uses a verification flag to identify trusted contacts. You need to find the total number of trusted contacts for each user.

A contact is considered trusted if the is_verified flag in the contacts table is set to 1.

Rules:

  • Only include users who have at least one trusted contact.
  • Output columns: user_id, user_name, trusted_contact_count.
  • Results must be sorted by user_id in ascending order.
Tests your understanding of
Grouping, Aggregation and Filtering

Input Tables

users
user_id(INTEGER)user_name(VARCHAR)
1Alice
2Bob
3Charlie
contacts
user_id(INTEGER)contact_id(INTEGER)is_verified(INTEGER)
1101
1110
1121
2131
3140
user_settings
user_id(INTEGER)privacy_level(VARCHAR)
1High
2Medium

Expected Output

user_id(INTEGER)user_name(VARCHAR)trusted_contact_count(INTEGER)
1Alice2
2Bob1

Tags

EasyASKED IN INTERVIEWGroupingAggregationFiltering
10-15 min
74%

Hints