Magicsheet logo

Friend Requests I: Overall Acceptance Rate

Easy
25%
Updated 8/1/2025

Asked by 1 Company

Topics

Friend Requests I: Overall Acceptance Rate

What is this problem about?

The Friend Requests I interview question involves two SQL tables: FriendRequest (tracking sent requests) and RequestAccepted (tracking accepted requests). You need to calculate the overall acceptance rate, which is the total number of unique accepted requests divided by the total number of unique sent requests. The result should be rounded to two decimal places. If there are no requests at all, return 0.00.

Why is this asked in interviews?

Meta (Facebook) uses this Database coding problem to test a candidate's ability to calculate business metrics. It evaluates your understanding of finding unique records (using COUNT(DISTINCT ...)) across different tables. It also checks if you can handle edge cases like division by zero, which is a critical skill for building robust data dashboards.

Algorithmic pattern used

This problem relies on Independent Subqueries and IFNULL.

  1. Count Sent: Find the total number of unique (sender_id, send_to_id) pairs in the FriendRequest table.
  2. Count Accepted: Find the total number of unique (requester_id, accepter_id) pairs in the RequestAccepted table.
  3. Calculate Ratio: Divide accepted by sent.
  4. Handle Zero: Use IFNULL (or COALESCE) to handle the case where the denominator is 0.

Example explanation

Sent Requests:

  • A -> B
  • A -> B (Duplicate send, count as 1)
  • C -> D Total unique sent = 2.

Accepted Requests:

  • A -> B
  • A -> B (Duplicate accept, count as 1) Total unique accepted = 1.

Ratio: 1/2=0.501 / 2 = 0.50.

Common mistakes candidates make

  • Joining Tables: Trying to JOIN the requests and accepts tables. This is unnecessary and often leads to incorrect counts due to duplicates or Cartesian products.
  • Ignoring Duplicates: Using COUNT(*) instead of counting unique pairs. A user might click "send" twice, but it's only one logical request.
  • Integer Division: In some SQL dialects, dividing two integers results in an integer (e.g., 1/2=01 / 2 = 0). You must cast to a float or multiply by 1.0.

Interview preparation tip

When calculating aggregate ratios across different stages of a funnel (like sent -> accepted), it's almost always safer and faster to calculate the numerator and denominator in separate subqueries rather than trying to join the tables.

Similar Questions